关于javascript原型链的记录

构造函数拥有名为prototype属性,每个对象都拥有__proto__属性,而且每个对象的__proto__属性指向自身构造函数prototype。
当调用某种方法或属性时,首先会在自身调用或查找,如果自身没有该属性或者方法,则会去它的__proto__属性中调用查找,也就是它构造函数的prototype中调用查找;

function Person(){}
var person = new Person();
console.log(person.protoPerson.prototype); //true
console.log(Person.proto
Function.prototype); //true
console.log(String.protoFunction.prototype); //true
console.log(Number.proto
Function.prototype); //true
console.log(JSON.protoFunction.prototype); //false
console.log(JSON.proto
Object.prototype); //true
console.log(Math.protoObject.prototype); //true
console.log(Function.proto
Function.prototype); //true
因为构造函数.prototype也是对象(称之为原型对象),因此也具有__proto__方法,所有的构造函数的原型对象都指向Object.prototype(除了Object.prototype自身);
console.log(Person.prototype.protoObject.prototype); //true
console.log(Object.prototype.proto
null); //true

posted @ 2018-11-05 11:33  赤島  阅读(226)  评论(0)    收藏  举报