String.prototype (Property)

The prototype for the String object that can be used to extend the interface for all String objects.


ECMAScript edition - 2
JavaScript - 1.1
JScript - 3.0
Internet Explorer - 4.0
Netscape - 3.0
Netscape Enterprise server - 3.0
Opera - 3.0
Property/method value type:String object
JavaScript syntax:-String.prototype

The prototype property refers to the built-in String prototype object.

The example demonstrates how to provide extensions to all instances of this class by adding a function to the prototype object.

Example code:

   // Define a function that extends the capabilities of String objects
   function reverse()
      myArray = new Array(this.length);
      for(myEnum=0; myEnum<this.length; myEnum++)
         myArray[myEnum] = this.substr(myEnum,1)
      return myArray.join("");
   // Register the new function
   String.prototype.reverse = reverse;
   // Create a string object and test the String.reverse() method
   myString = new String("ABCDEFGH");

See also:prototype property, String object, String.charAt(), String.charCodeAt(), String.constructor, String.indexOf(), String.lastIndexOf(), String.length, String.split(), String.substring(), String.toLocaleLowerCase(), String.toLocaleUpperCase(), String.toLowerCase(), String.toString(), String.toUpperCase(), String.valueOf()


ECMA 262 edition 2 - section

ECMA 262 edition 2 - section

ECMA 262 edition 2 - section 15.5.4

ECMA 262 edition 3 - section