JS - Inheritance
by Ben Clayton
JavaScript
function mybase(){
this.a=1;
this.b=4;
this.hello = function(){ return "Hi I'm mybase"}
return this;
}
function mychild(){
this.a=2;
this.hello = function(){ return "Hi I'm mychild"}
this.getboth = function(){
return this.hello() + " , " + this.__proto__.hello();
}
return this;
}
mychild.prototype = new mybase;
var obj = new mychild();
console.log("a=",obj.a);
console.log("b=",obj.b);
console.log("hello=",obj.hello());
console.log("Both=",obj.getboth());