Using 'call method' to call the constructor of base class : Inheritance : Object Oriented JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Object Oriented » Inheritance »

 

Using 'call method' to call the constructor of base class













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

function SubClass(sColor, sName) {
    BaseClass.call(this, sColor);

    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