In the example below, why is Dog.prototype.constructor = Dog
needed? I under we use:
Dog.prototype = Object.create(Animal.prototype)
to inherit the sayAnimal()
and any other functions added to the Animal
prototype but how does that effect the constructor? What would leaving it out do?
function Animal(gender) {
this.gender = gender;
}
Animal.prototype.sayAnimal = function() {
return "I am an animal"
}
function Dog(gender, barkSound) {
Animal.call(this, gender)
this.barkSound = barkSound
}
Dog.prototype = Object.create(Animal.prototype)
Dog.prototype.constructor = Dog