I'm just learning about prototypal inheritance and am a little confused about the use of Object.create(). I'm confused about why Object.create() is needed in the following code:
function Mammal (name){
this.name = name;
this.offspring = [];
}
Mammal.prototype.haveBaby = function (){
var baby = new Mammal('Baby ' + this.name);
this.offspring.push(baby);
return baby;
}
function Cat (name, color){
Mammal.call(this, name);
this.color = color;
}
Cat.prototype = Object.create(Mammal.prototype);
Does function Cat(name, color){ Mammal.call(this, name) }
not pass the on the methods from Mammal? Is that why we need Object.create()
?