> Function.call == Function.prototype.call
true
> Function.prototype == Function
false
Why do Function.prototype.* methods exist as Function.*? It seems inconsistent.
This isn't the case with any other primary type (Array.slice doesn't exist but Array.prototype.slice does).
A function is a set of code that performs a specific task and can be used whenever needed just by calling it. While using multiple function calls or recursion, the concept of a function call is very necessary to be known, for better understanding of the code.
Javascript Function call() The JavaScript Function call() method calls a function with a given this value and arguments provided individually. The call() method calls a function by passing this and specified values as arguments.
Because Function itself is the prototype of Function
console.log(Function instanceof Function);
console.log(Object.getPrototypeOf(Function) === Function.prototype);
So, all the functions in the Functions prototype are available in Function also.
Quoting the specification,
The Function prototype object is itself a Function object (its [[Class]] is "Function")
Another way to confirm this would be,
console.log(Function.call === Function.prototype.call);
it means that the Function.call object and Function.prototype.call object are the same.
console.log(Function.hasOwnProperty('call'));
it means that the Function object itself doesn't have call property.
console.log(Function.prototype.hasOwnProperty('call'));
it means that Function.prototype object has the call property.
Array.slicedoesn't exist butArray.prototype.slicedo
Because Array function's prototype is Function object, not the Array object.
console.log(Object.getPrototypeOf(Array) === Function.prototype);
That is why we get call, apply, bind etc on the Array function. It Array object had been the prototype of Array, then slice would have been available on the Array object also.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With