Inheritance snippet-2
by rishul matta
JavaScript
function a(b){
alert(a.length);
alert(arguments.length);
}
//a(1,2,3);
//below we have 3 constructors notice Capital casing of the names
function GrandDad(family){
this.family=family;
this.name="Grand";
this.myFunc=function(){
return this.name;
};
}
//GrandDad prototype points to object prototype lets override to string
GrandDad.prototype.toString=function(){
return "i have over ridden";
};
function Dad(middle){
this.middle=middle;
this.name="Dad";
}
function Child(name){
this.name=name;
}
//start inheritance
Dad.prototype= new GrandDad();
Child.prototype= new Dad();
//overwrite constructor
Dad.prototype.constructor= Dad;
Child.prototype.constructor= Child;
var obj = new Child("dude");
alert(obj.myFunc());
alert(obj.name);
//now make a new object and see what you get
var newObj= new Object();
alert(newObj.toString());