Tell us what’s happening:
I was wondering is the whole point of this exercise in the practical world; how to work with methods? Why don’t we see a constructor like the following? It won’t even let me even put a this.name = name in the new syntax. Is the new Object.creat() a replacement for that pattern? I must be missing something.
function Tree(name) {
this.name = name;
}
Your code so far
function Animal() { }
Animal.prototype = {
constructor: Animal,
eat: function() {
console.log("nom nom nom");
}
};
function Dog() { }
// Add your code below this line
Dog.prototype = Object.create(Animal.prototype);
let beagle = new Dog();
beagle.eat(); // Should print "nom nom nom"
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/object-oriented-programming/set-the-childs-prototype-to-an-instance-of-the-parent