解决构造函数的缺陷
时间:2021-09-12 10:50:51
收藏:0
阅读:26
index.js
function Animal(race) {
this.race = race;
}
Animal.prototype.eat = function () {
console.log(`${this.race} is eatting.`);
};
const bird = new Animal("bird");
const dog = new Animal("dog");
bird.eat();
dog.eat();
console.log(bird.eat === dog.eat); // true
原文:https://www.cnblogs.com/aisowe/p/15250362.html
评论(0)