If we have a parent object like:
var Animal = function(name) {
this.name = name;
return this;
}
and we use prototype
like:
Animal.prototype.Dog = function(){
console.log(this.name);
}
this just works great. But what I am trying to achieve is to inherit the parent property in child object like
Animal.prototype.Child = {
Dog : function(){
console.log(this.name);
}
}
How can we do this. I am trying to find it for two days. I've also tried:
Animal.prototype.Child = {
that:this,
Dog : function(){
console.log(this.that.name);
}
}
But here that
contains the window
object not the Animal
. Also
Animal.prototype.Child = {
Animal: new Animal('Puppy'),
Dog : function(){
console.log(this.Animal.name);
}
}
is NOT an option here.