Today look at the colleague's code, the latest version of the script library function definition method has changed, by the general function definition mode functions FFF () {} to () (para) anonymous method, after reviewing the data, analysis is as follows:
The initial way is:
App.Extent = function (__minx, __miny, __maxx, __maxy, _spatialReference) {}; |
After that, modify to format:
(function ($, app) { //使用参数app app.Extent = function (minx, miny, maxx, maxy, spatialReference) {};})(jQuery, App); |
Analysis:
Modified to be equivalent to
App.GetExtent=function($,app){ app.Extent = function (minx, miny, maxx, maxy, spatialReference) {};}App.GetExtent(jQuery, App); |
Or, you can simply look up and down in comparison:
(function($,app){ /***/})(jQuery,App)定义中$就是jQuery,app就是App;所以函数内容/***/中用到$和app,即为jQuery和App的调用! |
See an explanation on the net, feel very clear, for everyone to refer to, as follows:
(function () {}) () equivalent to defining function xx () {}, after calling XX ();
() is the highest priority, so first execute function () {}, which defines an anonymous function, equals Xx=function () {}, and then calls XX ();
Below reprint content from article: http://www.cnblogs.com/swjm119/archive/2011/12/19/2293125.html
Share some of the lessons learned when developing jquery plugins.
First, look at JQuery (function () {
});
All written as
JQuery (document). Ready (function () {});
Analysis: The meaning is to execute the Ready () method after the DOM has been loaded.
Second, look again
(function () {
}) (JQuery);
Analysis: It is actually an anonymous method of executing () (para), except that the jquery object is passed.
Iii. Summary
1. JQuery (function () {}), which holds the code for manipulating the DOM object, and the DOM object already exists when executing code. cannot be used to store code that develops plug-ins, because jquery objects are not passed, and external methods (functions) cannot be called by Jquery.method.
2. (function () {}) (JQuery), which is used to store the code to develop the plug-in, the DOM does not necessarily exist when executing the code, so be careful with the code that automatically performs the DOM operation directly.
3. (function ($) {...}) (JQuery) is actually an anonymous function that does not know that a friend can continue to look down.
This is actually anonymous function functions (ARG) {...} This defines an anonymous function that, when called with Arg, is written with parentheses and arguments after the function, and because of the precedence of the operator, the function itself needs to be enclosed in parentheses, namely: (function (ARG) {...}) (param) This is equivalent to defining an anonymous function with a parameter of ARG, and calling this anonymous function as a parameter (function ($) {...}) param (jquery) is the same, the reason why only use $ in formal parameters is to not conflict with other libraries, so the argument is using jQuery var fn = function ($) {...}; FN (jQuery);
Http://home.cnblogs.com/group/topic/928.html is the usual way to initialize a jquery object, and the popular point is to execute the code you need after the page is loaded, but this thing sometimes makes the page tick.
4. The summary is as follows:
(Funtion () {}) (); Execute the function immediately; it is equivalent to declaring a function, calling it directly after the declaration, and if the parameters are as follows:
(Funtion (str) {alert (str)}) ("Output")) ; equivalent: funtion outputfun (str) {alert (str);};o Utputfun ("Output");
The difference between jquery (function () {}) and (function () {}) (jquery)