(Function ($, jQuery, undefined) {}) (JQuery); Why should window and undefined be passed as arguments to it?
Because the ECMAScript executes the JS code from inside to outside, so the global variable window or jquery object is passed in, it avoids the outer to look for, improve efficiency. Undefined in the older generation of browsers is not supported, direct use will be error, JS framework to consider compatibility, so add a formal parameter undefined.
var 8 ; (function (window) { // 8 // 8 }) (window);
var 8 ; (Function (window, undefined) { alert (window.undefined); // 8 // Here the undefined parameter is local name is the undefined variable, the value is undefined}) (window);
Distinguish between the two ways: the first one is to find a window for each of the statements. The second is to pass the window as a parameter, and not to go to the window for each statement, it should be more efficient. So the latter, even if the outside people to define the undefined, the inside of the undefined is still unaffected. Presumably to minimize the impact of external variable definitions on the internals of the package.
Original reference from webmaster net http://www.software8.co/wzjs/Javascript/2525.html
// mode one = = ...; ...... }) (); // mode two // code goes here // way three var tmp = window; Tmp.property1 = ...; Tmp.property2 = ...; ...... }) ();
The efficiency of mode one is obviously the lowest, the way two and the way three should be similar. Passing the window as a parameter allows the statement inside the code to use the window directly in the argument without having to find the outermost object. If you want to set 100,000 properties for the window in the function, passing the argument in the past only needs to find the outermost object once. Without argument passing, the statement using the window will have to find the outermost object.
;(function ($, window, undefined) {} (Jquery,window)) Why you need to pass $,window,undefined these parameters inside