self-executing javascript anonymous function (function (window, document, undefined) {}) (window, document);

Since execution of the function using an anonymous action: (function (window, document, undefined) {}) (window, document);

1. First anonymous function (function () {}) (); to avoid conflicts in vivo function of exogenous variables (js execution order of the expression in parentheses to outside parentheses);

2. parentheses behind (window, Document) window is argument for receiving the window object (window object is a global environment); parentheses behind the function function (window, document, undefined) {} in the window It is a local variable, not the global window object. So write js can improve performance, reduce the scope chain query time (if used several times in the body of the function to the window object window object as an argument to pass in, it is very necessary;. If the internal functions do not need, then you do not need passing the parameter).;

? 3.function behind the parameter undefined what use is it actually in some older browsers, undefined is not supported, directly results in an error, so consider compatibility, you add a parameter undefined;

4. (function () {}) () is mainly used for storing the code developed plug, there is not necessarily DOM executes the code, the code is automatically performed directly DOM operations, ease of use;

 

 Simplified () (); represents a self-executing anonymous function

(function(window,document,undefined) {  
    //do something  
    console.log ( "I am the anonymous function on their own implementation of the Austrian!");  
})(window,document); 

  

Summary: to be perfect, hope supplement, not quite understand

Guess you like

Origin www.cnblogs.com/677a/p/11726510.html