__proto__ VS. JavaScript中的原型 [英] __proto__ VS. prototype in JavaScript
问题描述
此图再次显示每个对象都有一个原型。构造函数
函数Foo也有自己的__ proto __
,它是Function.prototype,
,而且它还通过其__ proto__引用
再次将属性改为
的Object.prototype。因此,重复,Foo.prototype只是Foo的显式
属性,它引用了b和c对象的原型。
This figure again shows that every object has a prototype. Constructor function Foo also has its own
__proto__
which is Function.prototype, and which in turn also references via its__proto__
property again to the Object.prototype. Thus, repeat, Foo.prototype is just an explicit property of Foo which refers to the prototype of b and c objects.
var b = new Foo(20);
var c = new Foo(30);
__ proto __
和<之间有什么区别? code>原型属性?
该图取自这里。
推荐答案
__ proto __
是查找链中用于解析方法等的实际对象。 prototype
是用于构建 __ proto __ <的对象/ code>当您使用
new
创建对象时:
__proto__
is the actual object that is used in the lookup chain to resolve methods, etc. prototype
is the object that is used to build __proto__
when you create an object with new
:
( new Foo ).__proto__ === Foo.prototype;
( new Foo ).prototype === undefined;
这篇关于__proto__ VS. JavaScript中的原型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!