I am currently facing an issue while trying to create a new class that inherits from Function. Specifically, I am encountering difficulties when attempting to call the .call method on instances of this new class.
To illustrate, let's say I have defined the following constructor:
function myFunc() {
Function.call(this);}
The prototype of myFunc is then set to be the same as Function:
myFunc.prototype = Function.prototype
Next, I create a new instance of this class:
var f = new myFunc()
When checking, it becomes evident that f.\__proto\__
equals Function.prototype
:
f.__proto__ === Function.prototype /=> true
As expected, the Function.prototype
includes a call method:
Function.prototype.call /=> ƒ call() { [native code] }
However, calling f.call(null)
results in an error:
f.call(null) /=> VM183:1 Uncaught TypeError: f.call is not a function
at <anonymous>:1:3
This situation raises the question of why f.call
does not seem to check f.__proto__
for a call method even though it should logically do so.