JS Advanced --- the local variables become global variables

How to become local variables global variables? 

The local variable to the window on it
 
 
Since the function call from the calling function ---
A one-time function - a statement at the same time, a direct call
    (function () {
      console.log("函数");
    })();

 

Local variables
After the page loads. This function is called from code execution over
    (function (parameter) { 
      var NUM = 10; // local variable 
    }) (argument); 
    the console.log (NUM);

 

The local variables to the window, then the local variable becomes a global variable
    (function (win) { 
      var NUM = 10; // local variables 
      // js is a dynamically typed language, the object attribute is not, there is a point 
      win.num NUM =; 
    }) (window); 
    the console.log (num);

Guess you like

Origin www.cnblogs.com/ZXH-null/p/12128219.html