by eiriklv · 9y ago · 0 comments
If you're doing a direct function call like myFunc() there is nothing "left" of the function call. But you might think of it as actually doing window.myFunc(), which again explains why this === window. In strict mode this behavior has been "fixed" so that this === undefined.
It's all about how a function is called.
(Spoilers: this == window, not what is left of the function call)
@getify explains it flawlessly, there are 4 modes: new, obj., bind/apply/call and default (window or error in strict mode)
Looking at a possible implementation of setTimeout makes it clearer:
function setTimeout(func, delay) {
// wait for the delay to complete..
func();
}
Here you can see that when the function is called there's nothing to the left of it.