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

function Person(){}
var person = new Person();
console.log(person.__proto__==Person.prototype);      //true
console.log(Person.__proto__==Function.prototype);    //true
console.log(String.__proto__==Function.prototype);    //true
console.log(Number.__proto__==Function.prototype);    //true
console.log(JSON.__proto__==Function.prototype);      //false
console.log(JSON.__proto__==Object.prototype);        //true
console.log(Math.__proto__==Object.prototype);        //true
console.log(Function.__proto__==Function.prototype);  //true

因为构造函数.prototype也是对象(称之为原型对象),因此也具有__proto__方法,所有的构造函数的原型对象都指向Object.prototype(除了Object.prototype自身);
console.log(Person.prototype.__proto__==Object.prototype); //true
console.log(Object.prototype.__proto__==null); //true

内容来源于网络如有侵权请私信删除
你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!