js 原型笔记

function A() {
  this.a = 'a';
}

A.prototype.b = 'b';

var a = new A();
console.log(a.a);

var b = {};
b.__proto__ = A.prototype;
A.call(b);
console.log(b.a);

__proto__指向创建该对象的构造函数的原型对象
prototype指向构造函数的原型对象

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注