What design pattern is this code in Javascript? -


what kind of design pattern , significance of using closure?

(function(){     // code here }).call(this);  

edit

then difference between above code , following this keyword still refer same object in both ways.

(function(){     // code here })();  

thats invoked function expression.

more info here: http://benalman.com/news/2010/11/immediately-invoked-function-expression/

the purpose run code while protecting scope (so variables declared within don't leak out global scope.

update

call sets value of this function being applied on. without it, value set window object, there set outer scope.


Comments

Popular posts from this blog

javascript - Count length of each class -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -