什么是原型

  • 原型实际是一个对象
  • prototype实际上是一个函数的属性,他也是一个对象,只有函数才有prototype属性,对象没有这个属性
var wumao = function() {}
var liumao = {}
console.log(wumao.prototype) // {...}
console.log(liumao.prototype) // undefined
  • 每个实例对象都有一个__proto__属性指向他的构造函数的prototype属性,也就是该对象的原型
  • 原型实际上是一个对象他也有自己的原型,即__proto__属性,这样层层向上,直到指向null,这样形成的一个链式结构就称为原型链

关系图

Last modification:March 10, 2021
If you think my article is useful to you, please feel free to appreciate