I have seen JavaScript written like this (it was at a demonstration, and I don’t have the actual code at hand, but it was implied this was normal):
(function() {
var a = 1;
this.sayA = function() {
alert(a);
}
}).call(this);
sayA();
I suppose it is written an an anonymous function so that the variable a
is not globally available.
What could the point of the .call(this)
be? Since this function was not nested, this
was just the window. How does it differ from just writing ()
at the end?