Compile the jQuery plug-in and jquery plug-in
The jQuery plug-in is actually a method and function called through the jQuery namespace.
JQuery plug-ins are divided into three types:
1. Plug-ins called through objects, such as var obj = $ ("# hello"); obj. plg (); extended through jQuery. fun. extend ()
2. The Global plug-in is called under the name of jQuery. For example, jQuery. trim () is extended through the jQuery. extend () method. This method is also used to set default parameters.
3. the selector plug-in expands the jQuery selector, such as: $ (". a "). the color (red) is red and the class is. the element of a is passed through jQuery. extend () method to expand
Closure in javascript:
Description: internal functions are allowed (function definitions and function expressions are located in another function), and these internal functions can access
All the local variables, parameters, and other declared internal functions of the external function. When one of these internal functions is called outside the external functions that contain them,
A closure is formed. For example:
function a(){var x=1;var b=function(){y=x;return y;}}var c=b
The jQuery plug-in utilizes the closure feature to allow internal temporary variables to affect the global space and to access external space variables within the plug-in, such as jQuery, $
Common plug-ins are:
(Function () {/* here is the implementation code */})();
Or yes.
; (Function ($) {var foo; // The local variable var bar = function () {/* internal functions of anonymous functions can access foo, even if you call bar outside the anonymous function, you can access foo, but you cannot directly access foo outside the anonymous function */$. BAR = bar; // escape the internal function bar () of the anonymous function to the globally accessible space. BAR () to access the internal function bar ()}) (jQuery );