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__
和prototype
有什么区别?
图取自dmitrysoshnikov.com .
注意:现在有 a 2nd edition (2017)到上面2010年的文章。
最佳答案
__proto__
是在查找链中用于解析方法等的实际对象。prototype
是用于构建 __proto__
的对象当您使用 new
创建对象时:
( new Foo ).__proto__ === Foo.prototype
( new Foo ).prototype === undefined
关于javascript - __proto__ VS。 JavaScript 中的原型(prototype),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9959727/