Three level inheritance by using the Hybrid Method : Inheritance : Object Oriented JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Object Oriented » Inheritance »

 

Three level inheritance by using the Hybrid Method













function Shape(iSides) {
    this.sides = iSides;
}
Shape.prototype.getArea = function (ss) {
    return 0;
};

function Triangle(iBase, iHeight) {
    Shape.call(this, 3);
    this.base = iBase;
    this.height = iHeight;
}

Triangle.prototype = new Shape();
Triangle.prototype.getArea = function () {
    return 0.5 this.base * this.height;
};
function Rectangle(iLength, iWidth) {
    Shape.call(this, 4);
    this.length = iLength;
    this.width = iWidth;

}

Rectangle.prototype = new Shape();
Rectangle.prototype.getArea = function () {
    return this.length * this.width;
};
var triangle = new Triangle(124);
var rectangle = new Rectangle(2210);

alert(triangle.sides);        //outputs "3"
alert(triangle.getArea());    //outputs "24"

alert(rectangle.sides);       //outputs "4"
alert(rectangle.getArea());   //outputs "220"







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Object Oriented
» Inheritance