anonymous functions
(Function (window, undefined) {}) (window)
The reason for passing in the window variable is that the window is changed from a global variable to a local variable, and the scope chain is not returned to the top-level scope for faster access to the window.
Reasons for increasing undefined in the argument list: Make sure that undefined is really undefined in the scope of the self-invocation of the anonymous function.
Benefits:
To create a private namespace, methods and variables within a function body do not affect global space, and do not conflict with other program variables and methods, which are legendary non-polluting global variables.
2. function extension.
(function (window, undefined) { var jquery = function () { return new jquery.fn.init (); } jQuery.fn = jQuery.prototype = { version: ' 1.8.3 ', init: function () { return this; } } jquery.fn.init.prototype = jquery.fn; jquery.extend = Jquery.fn.extend = function (obj) { for (var n in obj) this[n] = obj[n]; return This; } jquery.fn.extend ({ test: function () { Console.log (' hello world!! '); } }); Window.jquery = window.$ = jquery;}) (window)
Learn JavaScript through the jquery source code (II)