(function(window, undefined){ //jQuery code; })(window);
Why incoming undefined?
1. no incoming undefined:
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>Test HTML Page</title> 5 <script type="text/javascript"> 6 7 var undefined = "你好"; 8 ( 9 function(window){ 10 alert(undefined); 11 } 12 )(window); 13 14 </script> 15 </head> 16 <body> 17 <!-- 这里放入内容 --> 18 </body> 19 </html>
Implementation of the results in IE8:
2. was introduced to undefined:
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>Test HTML Page</title> 5 <script type="text/javascript"> 6 7 var undefined = "你好"; 8 ( 9 function(window, undefined){ 10 alert(undefined); 11 } 12 )(window); 13 14 </script> 15 </head> 16 <body> 17 <!-- 这里放入内容 --> 18 </body> 19 </html>
Using IE8 Test:
Explanation:
Introduced to undefined, the var undefined = "hello"; this will not work in an anonymous call from function block.
the reason:
(function(window,undefined){})(test);
Anonymous functions shaped two parameters, a window, a undefined.
Since the time of the call, only to pass an argument test,
Therefore, anonymous function of the second parameter is automatically assigned the undefined, i.e., window = test, undefined = undefined.