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:
| 12345678 |
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:
| 123 |
(function(){/* Here is the implementation code */})(); |
Or yes.
| 12345678910 |
;(function($){var foo;// Local variablevar bar=function(){ /* All functions inside an anonymous function can access foo. Even if the bar is called outside the anonymous function, foo can be accessed, but outside the anonymous function. Direct access to foo is not possible. */ $.BAR=bar;// Let the internal function bar () of the anonymous function escape to the global accessible space, so that you can access the internal function BAR () through jQuery. bar ()}})(jQuery); |