Revision: 2654
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at March 20, 2007 08:02 by 1man
Initial Code
//Extending an existing object
function yourMethod(){
//statements
}
//Attach it to the String Object
String.prototype.methodName=yourMethod;
//Usage
var myVariable = "My String Here!"
myVariable.methodName();
//Extending a custom object
//Create custom object
function myObject() {
//statements
}
//Create custom method
function customMethod(){
//statements
}
//Create custom property
function customProperty() {
//statements
}
//Attach the property and method
myObject.prototype.methodName=customMethod;
myObject.prototype.prpertyName=customProperty;
Initial URL
Initial Description
Extend a custom object, and a pre-defined object(e.g. string) using .prototype available in JS.
Initial Title
Extending Objects and Custom Objects using .prototype
Initial Tags
object
Initial Language
JavaScript