Mega Code Archive

 
Categories / JavaScript Tutorial / Object Oriented
 

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();