一句话说清楚 __proto__和prototype

prototype是用来让实例构建proto

先看一张图

一句话说清楚 __proto__和prototype_第1张图片
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)