TL;DR
__proto__
is a property of an object
which enables you to look up in the prototype chain. While prototype
is a property of a Function
which enables you to add shareable functionalities to a constructor function.
Long Answer
Understand this from an example, let's say you create a constructor function.
function A() {}
and then create an instance of it, var a = new A()
.
Then, add a function as following:
A.prototype.getA = function () { return 'A'; }
.
Now, if you try to access a.getA()
, you'll get the result, i.e. getA
will be executed.
But how does it know about the function getA
even though getA
has been added after the instance a
was created. It's because of using __proto__
, you can traverse up in the chain (you must have heard about prototype chaining).
Technically, __proto__
is a property of an object, while prototype
is a property of function
. But how could functions
have property? Because everything in JavaScript is converted implicitly to an object. Ever wondered how could you something like this: 'test'.toUpperCase()
? Isn't string literals are 'not object' and they are primitives?
Read this for reference: http://jayendra.co.in/objects-in-javascript/
Now to answer your question:
What does Function.prototype.__proto__
mean?
You are trying to access the prototype
property of Function
constructor function. Remember, prototype
itself is an object
, so you can access properties like constructor
and __proto__
.
Function.prototype.__proto__ === Object.prototype
To enable chaining, when you access __proto__
property, you are looking up!
Any function can access all the properties of an object. How?
A property of Object
, let's say toString
. You can do, A.toString() // A created at the start
. But we never created a function toString
for A
constructor function!