欢迎访问我的博客,目前从事Machine Learning,欢迎交流

JS/javascript中的prototype和__proto__

// 创建一个Dog构造函数
function Dog(name, age) {   //
  this.name = name
  this.age = age
}

Dog.prototype.eat = function() {   //
  console.log('肉骨头真好吃')
}

// 使用Dog构造函数创建dog实例
const dog = new Dog('旺财', 3)

 

 

 

图by @修言(掘金小册:JavaScript 设计模式核⼼原理与应⽤实践

 

dog.__proto__和Dog.prototype 均指向function Dog,也就是①

posted @ 2019-12-25 18:47  有蚊子  阅读(324)  评论(0编辑  收藏  举报