this snippet implements "string".trim() in Javascript, as found in many other languages.

if(!String.prototype.trim) {
  String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
  }
}

another for basename():

if(!String.prototype.basename) {
  String.prototype.basename = function() {
    return this.replace(/^.*\//, '');
  }
}