解决构造函数的缺陷

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