View Single Post
Newbie Member
10Mar2009,08:16  
prasanna_gg's Avatar
Hi Pradeep,

Nice solution. Although it could be extended nicely so it works natively in Javascript. JS provides a way to create prototype functions easily.

Here is the code:

Code:
String.prototype.trim = function() {  return this.replace(/^\s+|\s+$/g, '');  }
This method can be called like any in-built javascript function - string.trim() instead of trim(string)!