美文网首页
一句话说清楚 __proto__和prototype

一句话说清楚 __proto__和prototype

作者: MetaZZZZ | 来源:发表于2017-03-18 10:40 被阅读26次

prototype是用来让实例构建proto

先看一张图

Paste_Image.png
图中的Foo是构造函数, b和c是从Foo new出来的实例
这么一看,其实看不出proto和prototype什么差别, 仔细看, 只有构造函数才有prototype
__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:

就是说prototype是用来让实例构建proto

( new Foo ).__proto__ === Foo.prototype
( new Foo ).prototype === undefined

相关文章

网友评论

      本文标题:一句话说清楚 __proto__和prototype

      本文链接:https://www.haomeiwen.com/subject/pcdunttx.html