Reset an Inherited Constructor Property

Reset an Inherited Constructor Property
0.0 0

#1

Tell us what’s happening:

Your code so far


function Animal() { }
function Bird() { }
function Dog() { }

Bird.prototype = Object.create(Animal.prototype);
Dog.prototype = Object.create(Animal.prototype);

// Add your code below this line
Bird.prototype= function Animal(){

};



let duck = new Bird();
let beagle = new Dog();

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/object-oriented-programming/reset-an-inherited-constructor-property


#2

Remove the code you added and instead add two lines similar to this:

Bird.prototype.constructor=Bird;

The second line is for the beagle which looks very similar to the bird one.
Hope this helps.


#3

The issue is in the previous challenge of the current challenge where you are right now ,wechanged the animal.prototype to Bird by Object.create method so Bird inherited Animal’s whole prototype , this is cool but if we want to check who is the constructor of Bird instances like duck object we will have that the constructor is Animal constructor function rather than the Bird constructor .
so to fix that we have to change the Bird.prototype.constructor=Bird;,here we let all the things inherited from Animal prototype but we changed only the prototype of it to the real constructor wich is Bird. I hope this helps .