
1. 任何函数都具有一个 prototype 属性,该属性是一个对象。
function F () {}console.log(F.prototype) // => objectF.prototype.sayHi = function () {console.log('hi!')}
- 构造函数的
prototype 对象默认都有一个constructor属性,指向prototype对象所在函数。console.log(F.prototype.constructor === F) // => true
3. 通过构造函数得到的实例对象内部会包含一个指向构造函数的prototype对象的指针__proto__。var instance = new F() console.log(instance.__proto__ === F.prototype) // => true console.log(instance.__proto__.constructor==F); console.log(instance.__proto__.constructor === F.prototype.constructor) // => true <img src="media/yuanxin.png" alt="">
4.总结
1) 任何函数都具有一个 prototype 属性,该属性是一个对象
2) 构造函数的 prototype 对象默认都有一个 constructor 属性,指向 prototype 对象所在函数
3) 通过构造函数得到的实例对象内部会包含一个指向构造函数的 prototype 对象的指针 proto
4) 所有实例都直接或间接继承了原型对象的成员
5) 构造函数的原型对象(prototype)中的属性和方法是可以被实例对象直接访问的
