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?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…