构造函数拥有名为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__== .prototype); //true
console.log(Math.__proto__== .prototype); //true
console.log(Function.__proto__==Function.prototype); //true
因为构造函数.prototype也是对象(称之为原型对象),因此也具有__proto__方法,所有的构造函数的原型对象都指向 .prototype(除了 .prototype自身);
console.log(Person.prototype.__proto__== .prototype); //true
console.log( .prototype.__proto__==null); //true
继续阅读与本文标签相同的文章
-
安!排!微信聊天记录的最佳恢复方法,拿走不谢!
2026-05-19栏目: 教程
-
一线丨滴滴与清华成立未来出行联合研究中心
2026-05-19栏目: 教程
-
如何监管数字健康和人工智能产品?FDA新发布两份指南予以明确
2026-05-19栏目: 教程
-
Linux系统权限管理
2026-05-19栏目: 教程
-
滴滴与清华成立未来出行联合研究中心
2026-05-19栏目: 教程
