Hello this challenge is really hard to understand can someone help me explaining it step by step
remember to set the constructor property when changing the prototype
Hello this challenge is really hard to understand can someone help me explaining it step by step
remember to set the constructor property when changing the prototype
The prototype property of a constructor function has a property called constructor which tells by which constructor a object was created.
consider a Dog() constructor.
function Dog(name) {
this.name = name;
}
its prototype will look something like
{
constructor : Dog
}
by default
But if you manipulate the prototype like
Dog.prototype = {
numLegs: 4,
eat: function() {
console.log("nom nom nom");
},
describe: function() {
console.log("My name is " + this.name);
}
};
The constructor property will also be overwritten. So its prototype will look something like
{
constructor : Object
}
To avoid this you have to manually set the constructor property
Dog.prototype.constructor = Dog
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.