If I try to add a method to prototype of an object, it doesn't work with this:
const dog = {
color: 'black',
bread: 'Spitz',
}
dog.prototype.hello = function() { // Doesn't work
return `Hello, I'm a ${black} dog.`
}
console.log(dog);
But it works if I use __proto__
instead of prototype:
const dog = {
color: 'black',
bread: 'Spitz',
}
dog.__proto__.hello = function() { // Works
return `Hello, I'm a ${black} dog.`
}
console.log(dog);
Why is that?