I would like to share some of my experiences when developing jquery plug-ins.
I. First read
Jquery (function (){
});
Write All
Jquery (document). Ready (function (){
});
It means that the ready () method is executed after the Dom is loaded.
2. Check again
(Function (){
}) (Jquery );
It is actually executing the () (Para) anonymous method, but passing the jquery object.
Iii. Summary
Jquery (function () {}); used to store the code that operates the DOM object. When the code is executed, the DOM object already exists. It cannot be used to store the code of the Development plug-in. Because the jquery object is not passed, the method (function) cannot be called externally through jquery. method ).
(Function () {}) (jquery); used to store the code of the Development plug-in. dom does not necessarily exist when executing the code. Therefore, use the code that directly performs Dom operations with caution.
(Function ($) {...}) (jquery) is actually an anonymous function. If you don't know it, you can continue reading it.
Here is actually the anonymous function (ARG ){...} this defines an anonymous function. When the parameter is Arg and the function is called, brackets and real parameters are written behind the function. Because of the operator priority, the function itself also needs to be enclosed in parentheses: (function (ARG ){...}) (PARAM) This is equivalent to defining an anonymous function with the parameter Arg and using Param as a parameter to call this anonymous function ($ ){...}) (jquery) is the same. The reason why $ is used only in the form parameter is to avoid conflicts with other libraries, so the real parameter uses jquery var fn = function ($) {....}; FN (jquery );
Http://home.cnblogs.com/group/topic/928.html
Is the usual method for initializing jquery objects ..
In layman's terms, the code you need is executed after the page is loaded.
However, sometimes this will make the page beat,
(Funtion () {}) (); execute the function immediately. It is equivalent to declaring a function and calling it directly after the declaration. If the parameter is as follows:
(Funtion (STR) {alert (STR)}) ("output"); equivalent to: funtion outputfun (STR) {alert (STR );}; outputfun ("output ");