/ Published in: JavaScript

Extend a custom object, and a pre-defined object(e.g. string) using .prototype available in JS.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//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;
Comments
