While looking at code on github, I found the following:
(function() {
}).call(this);
This is clearly a self invoking anonymous function. But why is it written this way? I'm used to seeing the canonical variant (function() {})()
.
Is there any particular advantage to using .call(this)
for a self invoking anonymous function?
Edit: It looks like some commonjs environments set this
to a non-global value at the top level of a module. Which ones, and what do they set this
to that you might want to preserve?