Prototype
// Constructor of the MyObject function MyObject(name, size){
this.name=name;
this.size=size;
}
// Add a function to the prototype
MyObject.prototype.tellSize=function{
alert(“size of “ + this.name+” is “ + this.size);
}
// Create an instance of the object. The new object has tellSize() method. var myObj=new MyObject(“Sang”, “30 inches”);
myObj.tellSize();
SEE VIDEO
SEE VIDEO
0 Responses So Far: