Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
218 views
in Technique[技术] by (71.8m points)

javascript - __proto__VS。 JavaScript原型(__proto__ VS. prototype in JavaScript)

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.

(构造函数Foo还具有自己的__proto__ ,即Function.prototype,而该__proto__又通过其__proto__属性再次引用了Object.prototype。)

Thus, repeat, Foo.prototype is just an explicit property of Foo which refers to the prototype of b and c objects.

(因此,重复一遍,Foo.prototype只是Foo的显式属性,它引用b和c对象的原型。)

var b = new Foo(20);
var c = new Foo(30);

What are the differences between __proto__ and prototype ?

(__proto__prototype什么区别?)

在此处输入图片说明

The figure was taken from dmitrysoshnikov.com .

(该图取自dmitrysoshnikov.com 。)

  ask by 0x90 translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

__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 :

(__proto__是在查找链用来解决方法,实际的对象等prototype是用于构建对象__proto__当你创建一个对象与new :)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...