javascript 将Prototype更改为新对象

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 将Prototype更改为新对象相关的知识,希望对你有一定的参考价值。

// adding properties to the prototype individually
Bird.prototype.numLegs = 2;

// a more efficient way is to set the prototype to a new object that already contains the properties.
// this way, the properties are all added at once
Bird.prototype = {
  numLegs: 2, 
  eat: function() {
    console.log("nom nom nom");
  },
  describe: function() {
    console.log("My name is " + this.name);
  }
};

以上是关于javascript 将Prototype更改为新对象的主要内容,如果未能解决你的问题,请参考以下文章