Why if F
- simple function:
F.prototype !== F.__proto__
but
Function.prototype === Function.__proto__
?
Why if F
- simple function:
F.prototype !== F.__proto__
but
Function.prototype === Function.__proto__
?
Copyright © 2021 Jogjafile Inc.
Suppose you're designing an API for all functions. So you define that every function should have the method
call
. You create an object with such method:Then for all functions to share this functionality, you have to add it to
.prototype
property of a Function constructor, so that all instances of a Function inherit it. So you do the following:Now, when you create a function
F
, it will have have its.__proto__
set tofproto
:Now you decide that all instances created using
F
constructor, should have a methodcustom
, so you create an objectiproto
with the property and set it as a prototype for all instances ofF
usingprototype
property:So now it should be clear that
F.__proto__
andF.prototype
are not the same object. And this is essentially what happens under the hood when you declare a function:Is an exceptional case because
Function
constructor should have all methods available for function instances, and henceFunction.__proto__
, but all share these methods with function instances, henceFunction.prototype
.