JavaScript & DHTML - How to define a function that extends the capabilities of String objects?
<HTML> <HEAD> </HEAD> <BODY> <SCRIPT> // 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) } myArray.reverse(); 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"); document.write(myString.reverse()) document.write("<BR>") </SCRIPT> </BODY> </HTML>
Category: | JavaScript & DHTML |
<< Go back