gotchajavascriptCritical
What is the difference between `.prototype` and `.__proto__`?
Viewed 0 times
__proto__andbetweentheprototypedifferencewhat
Problem
This figure again shows that every object has a prototype. Constructor
function
and which in turn also references via its
the
property of
What are the differences between
The figure was taken from dmitrysoshnikov.com.
Note: there is now a 2nd edition (2017) to the above 2010 article.
function
Foo also has its own __proto__ which is Function.prototype,and which in turn also references via its
__proto__ property again tothe
Object.prototype. Thus, repeat, Foo.prototype is just an explicitproperty 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?The figure was taken from dmitrysoshnikov.com.
Note: there is now a 2nd edition (2017) to the above 2010 article.
Solution
__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 === undefinedCode Snippets
( new Foo ).__proto__ === Foo.prototype
( new Foo ).prototype === undefinedContext
Stack Overflow Q#9959727, score: 988
Revisions (0)
No revisions yet.