Extending the native String() class
You can see parts of this class in use in Configurable greeking and Using JS code libraries, part 2.
/* Code from "Developing Featherweight Web Services with JavaScript" http://feather.elektrum.org/ (c)An Elektrum Press, retain this notice License: http://feather.elektrum.org/appendix/licenses.html */ // extend String objects to do ucFirst() like Perl String.prototype.ucFirst = function () { return this.substr(0,1).toUpperCase() + this.substr(1,this.length); } // extend String objects to do reverse() String.prototype.reverse = function () { var tmp = this.split(''); tmp.reverse(); return tmp.join(''); } // snip whitespace off front and back of string String.prototype.snip = function () { return this.replace(/^\s+|\s+$/g, ''); }
Live tests
All original content is ©2004-2005 an elektrum press, all
rights reserved. For code use, please see Licenses and terms of use.