All new properties and methods of the subclass must come after the assignment of the prototype property : Inheritance : Object Oriented JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Object Oriented » Inheritance »

 

All new properties and methods of the subclass must come after the assignment of the prototype property













function SubClass() {
}

SubClass.prototype = new BaseClass();

SubClass.prototype.name = "";
SubClass.prototype.sayName = function () {
    alert(this.name);
};
var objA = new BaseClass();
var objB = new SubClass();
objA.color = "red";
objB.color = "blue";
objB.name = "MyName";
objA.sayColor();
objB.sayColor();
objB.sayName();







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Object Oriented
» Inheritance