Using apply function to call base constructor
|
|
<html> <head> <title>Example</title> </head> <body> <script type="text/javascript"> function BaseClass(sColor) { this.color = sColor; this.sayColor = function () { alert(this.color); }; }
function SubClass(sColor, sName) { BaseClass.apply(this, arguments); 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();
</script>
</body> </html>
|
|
|
HTML code for linking to this page:
Related in same category :
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|