Developing Feather-Weight Webservices with JavaScript

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

« Extending the native Date() class · Extending the native Array() class »
Google
 
Web Developing Featherweight Web Services with JavaScript
This is version 0.57b of this manual. It is a beta version with some gaps. We are grateful for feedback.

The code is the manual has not yet been fully tested against Internet Explorer. Bug reports are welcome.
An Elektrum Press Online