I am working inheritance in JavaScript, here, have created two objects. on the below code, when try to alert as alert(newOnj.whatAreYou());
, now, it is working fine. But, when i try to alert alert(newOnj.whatAreYounow());
, now, am getting error as 'newOnj.whatAreYounow is not a function'
. Actually, have inherited parent class to child class as subGadget.prototype = new Gadget();
. what is the thing that i haven't
understood here? please
function Gadget() {
this.name = "Alex";
this.color = "red";
this.whatAreYou = function(){
return 'I am a ' + this.color + ' ' + this.name;
}
}
function subGadget() {
this.whatAreYounow = function(){
return 'Now, I am a ' + this.color + ' ' + this.name;
}
}
subGadget.prototype = new Gadget();
var newOnj = new Gadget();
alert(newOnj.whatAreYounow());