Skip to content

Instantly share code, notes, and snippets.

@chekit
Created June 9, 2015 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chekit/238d7abe18ee93e02987 to your computer and use it in GitHub Desktop.
Save chekit/238d7abe18ee93e02987 to your computer and use it in GitHub Desktop.
Add trim() method to String.prototype

Add the following code to add trim functionality to the string.

if ( typeof String.prototype.trim !== 'function' ) {
  String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, ''); 
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment