This works:
function Bird(name){
Animal.call(this,name);
this.speak = function(){
console.log("Tweeet!");
}
}
Bird.prototype.constructor = Animal;
This throws "Cannot set property 'constructor' of undefined"
function Bird(name){
Animal.call(this,name);
this.speak = function(){
console.log("Tweeet!");
}
this.prototype.constructor = Animal;
}
Why would that be? In the second example, this should be Bird as I have called the function with new, so I should be able to set the prototype of this. What am I missing here?
thisinside function - object, so it don't have prototype property, but if you changethistoBirdall should work