Since this function was not nested, this was just the window. How does it differ from just writing () at the end?
No - not in strict mode:
- If the function code is strict code, set the
ThisBinding to thisArg.
- Else if
thisArg is null or undefined, set the ThisBinding to the global object.
- …
In strict mode, the this is just directly set to the given value, which is undefined for a normal call. Therefore, .call(this) is used to pass the global object explicitly in. You can try this in the console:
> (function() { "use strict"; console.log(this); })()
undefined
> (function() { "use strict"; console.log(this); }).call(this)
Window
It might not make a difference for sloppy code, but it's a good practise and future-compatible :-)