Hi,
Can anyone explain why my print to the console returns undefined with the following code:
function Dog(name) {
this.name = name;
}
let terrier = new Dog("John");
Dog.prototype = {
constructor: Dog,
numLegs: 4
};
console.log(terrier.numLegs);
I would expect it to work like this does:
function Dog(name) {
this.name = name;
}
let terrier = new Dog("John");
Dog.prototype.numLegs = 4;
console.log(terrier.numLegs);
My understanding was setting prototype to a new object was a quick way than setting each property individually, unless I’ve missed something?
Many thanks,
Fraser