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
.prototypeproperty 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
Fconstructor, should have a methodcustom, so you create an objectiprotowith the property and set it as a prototype for all instances ofFusingprototypeproperty:So now it should be clear that
F.__proto__andF.prototypeare not the same object. And this is essentially what happens under the hood when you declare a function:Is an exceptional case because
Functionconstructor should have all methods available for function instances, and henceFunction.__proto__, but all share these methods with function instances, henceFunction.prototype.