19
为什么需要在同一行上调用匿名函数?
我读了一些关于闭包的文章,到处都看到了,但是没有明确的解释它是如何工作的-每当我被告知要使用它时……: // Create a new anonymous function, to use as a wrapper (function(){ // The variable that would, normally, be global var msg = "Thanks for visiting!"; // Binding a new function to a global object window.onunload = function(){ // Which uses the 'hidden' variable alert( msg ); }; // …