Created
February 12, 2017 21:22
-
-
Save m-x-k/0da2b9b8b1c02205124a229a826f5efc to your computer and use it in GitHub Desktop.
Javascript augment String prototype to include trim function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function.prototype.method = function (name, func) { | |
this.prototype[name] = func; | |
return this; | |
}; | |
String.method('trim', function ( ) { | |
return this.replace(/^\s+|\s+$/g, ''); | |
}); | |
document.writeln('"' + " neat ".trim( ) + '"'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment