Tell us what’s happening:
as sir you can see that i have created an object name doggy , in the prevoius challenge it was taught that prototype are used add properties for the object , main focus is to not get code repeated every time . it is used to share properties with all other object created , but i have a doubt here
as i created an object name doggy , so when i print object why not all object all properties are not prrinted why only own properties get printed not prototypes ???
Your code so far
function Dog(name) {
this.name = name;
}
// Modify the code below this line
Dog.prototype = {
numLegs: 4,
eat: function() {
console.log("nom nom nom");
},
describe: function() {
console.log("My name is " + this.name);
}
};
const doggy = new Dog("german shepherd")
console.log(doggy);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36
.
Challenge: Remember to Set the Constructor Property when Changing the Prototype
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/object-oriented-programming/remember-to-set-the-constructor-property-when-changing-the-prototype