📜  在 Dog 原型上定义构造函数属性. - Javascript代码示例

📅  最后修改于: 2022-03-11 15:01:44.035000             🧑  作者: Mango

代码示例1
function Dog(name) {
  this.name = name;
}
Dog.prototype = {
  constructor: Dog,
  numLegs: 4,
  eat: function() {
    console.log("nom nom nom");
  },
  describe: function() {
    console.log("My name is " + this.name);
  }
};