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 - Unusual behaviour when drawing lots of images onto a large canvas -

how can i manage url using .htaccess in php? -

javascript - Chart.js - setting tooltip z-index -