I have checked many similar questions on stackoverflow, such as call.call 1 , call.call 2, but I am a newcomer, and I cannot make comment anywhere. I hope I can find a comprehensive and thorough explanation of how the JavaScript interpreter execute these functions, with opening a new question here.
Here are some examples:
function my(p) { console.log(p) }
Function.prototype.call.call(my, this, "Hello"); // output 'Hello'
The above example is a standard usage of Function.prototype.call, which is easier to understand. my understanding is: 'my' as an function object executes its inherited method 'Function.prototype.call' ie. my.(Function.prototype.call) => my.call(this, 'Hello')
Function.call.call(my, this, "Hello") // output 'Hello'
I am confused here, in comparison with the above example. I do not know how JavaScript interpreter works here. 'my' sees Function.call and Function.prototype.call as same method?
Function.prototype.call(my, this, 'Hello2') // output nothing
Function.call(my, 'Hello2') // output nothing
I cannot explain why this statement does not throw an error? In fact, I do not know how Function.prototype.call as a method works.
Function.prototype.call.call.call(my, this, "Hello3"); // output 'Hello3'
I cannot explain how the JavaScript interpreter interpretes the above statement? interpreting 'call' from right to left? then what does my.(Function.prototype.call.call) mean?
Function.prototype.call.call.call.call(my, this, "Hello4"); // output 'Hello4'
why I can put any number of '.call' here, and the output is the same? Does not each call consumes an argument as 'this' object, which should imply only three arguments are not enough? a similar question as the immediately above one
Then more examples:
var $ = Function.prototype.call
$(my, this, 'Hello5') // Exception: TypeError: Function.prototype.call called on incompatible Proxy
why it does not output nothing, just as one above example?
var v = Function.prototype.call.call
v(my, this, 'Hello6') // Exception: TypeError: Function.prototype.call called on incompatible Proxy
Does it mean, when use variable v, then JavaScript interpreter tries to interpret v isolatedly, without seeing there are arguments following? Then the interpreter thinks the 'this' is global variable 'window'? I do not know how the interpreter works differently between v() and Function.prototype.call.call()
Can anyone help, please? Thanks!