Monday, 12 March 2018

__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. 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);


What are the differences between __proto__ and prototype?



enter image description here



The figure was taken from dmitrysoshnikov.com.



Answer



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

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...