Example
Differences between the two methods in jQuery
| The code is as follows: |
Copy code |
/* Make sure that jQuery can be referenced correctly, because $ may be redefined outside the anonymous function, Passing jQuery as a parameter to an anonymous function ensures that $ in the function is jQuery. */ (Function ($ ){ // Code Here... }) (JQuery) /* $ (Document). ready () refers to a function passed to $ (). This function will be executed when DOM loading is complete. */ $ (Function (){ // Code Here... }) |
Most of the time,
| The code is as follows: |
Copy code |
(Function ($ ){...}) (Jquery ); |
In the context environment, the parameter jquery does not exist. Therefore, in the jquery anonymous function, the user creates a jquery object.
I will give a brief description here,
| The code is as follows: |
Copy code |
(Function ($ ){...}) (Jquery ); And A = function ($ ){...}; A (jquery ); |
Equivalent.
Therefore, this method is used to allow anonymous functions to be executed immediately.