Class combination with prototype : Combination : Object Oriented JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Object Oriented » Combination »

 

Class combination with prototype

















<html>
<head>
<title>Example</title>
</head>
<body>
<script type="text/javascript">
function BaseClass(sColor) {
    this.color = sColor;
}

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

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

SubClass.prototype = new BaseClass();

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


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

</script>

</body>
</html>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Object Oriented
» Combination