let animal = {
name: 'animal',
eat: function (food) {
console.log(this.name + ' eats ' + food);
}
}
let rabbit = {
__proto__: animal,
name: 'rabbit',
eat: function() {
this.__proto__.eat('carrot');
}
}
rabbit.eat(); // "animal eats carrot"
this.__proto__.eat.call(this, 'carrot');
let animal = {
name: 'animal',
eat: function (food) {
console.log(this.name + ' eats ' + food);
}
}
let rabbit = {
__proto__: animal,
name: 'rabbit',
eat: function() {
this.__proto__.eat.call(this, 'carrot');
}
}
let whiteRabbit = {
__proto__: rabbit,
name: 'white rabbit',
eat: function() {
this.__proto__.eat.call(this);
}
}
whiteRabbit.eat(); // RangeError: Maximum call stack size exceeded