Adding new properties and methods to the child class : Inheritance : Object Oriented JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Object Oriented » Inheritance »

 

Adding new properties and methods to the child class







All new properties and methods must be added after the line that deletes the new method.








function BaseClass(sColor) {
    this.color = sColor;
    this.sayColor = function () {
        alert(this.color);
    };
}


function SubClass(sColor, sName) {
    this.newMethod = BaseClass;
    this.newMethod(sColor);
    delete this.newMethod;

    this.name = sName;
    this.sayName = function () {
        alert(this.name);
    };
}

var objA = new BaseClass("red");
var objB = new SubClass("blue""MyName");
objA.sayColor();
objB.sayColor();
objB.sayName();







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Object Oriented
» Inheritance