1.(function($){...})(jQuery);
(1), the principle:
This is actually an anonymous function, as follows:
function(arg){...}
This defines an anonymous function parameter is Arg; functions are invoked, in the back bracket and write function arguments, since the priority of the operator, but also the function itself need parentheses, i.e. (function (arg) { ...}) (param)
This is equivalent to arg parameter defines a anonymous function, and param as a parameter to call the anonymous function;
And (function ($) {...}) (jQuery) is the same, the only reason to use $ parameter, in order not to conflict with other libraries, the arguments with jQuery
Corresponds to the function output (s) {...}; output (jQuery); or var fn = function (s) {...}; fn (jQuery);
(2) the role of (useful):
The greatest benefit of such an approach is the formation of closures. In (function ($) {...}) (jQuery) in the internal functions and variables defined only in
Valid within this range.
2 $ (function () {...});. JQuery (function ($) {...}); $ (document) .ready (function () {...}) is the same as the role of the three of;
The document has finished loading function performed later.