jquery plugins are actually methods and functions that are called through the namespace of jquery.
jquery plugins are divided into three types:
1. Plug-ins called by objects such as: Var obj=$ ("#hello"); OBJ.PLG (); Through the JQuery.fun.extend () method to expand
2. Global plug-ins, in the name of the JQuery downgrade, such as: Jquery.trim () through the Jquery.extend () method to expand, this method is also used to set the default parameters
3. Selector plug-in, expand the jquery selector, such as: $ (". a"). Color (red) selects the red and the elements of class. A are extended by the Jquery.extend () method.
Closures in javascript:
Description: Allows the use of intrinsic functions (function definitions and function expressions in another function body), and these intrinsics can access the
External functions all local variables, arguments, and other intrinsic functions of the Declaration, when one such intrinsic function is called outside the outer function containing them.
Will form closures. Like what:
function A () {var x=1;var b=function () {Y=x;return y;}} var c=b
The jquery plug-in is the use of the characteristics of closures, both internal temporary variables can affect the global space, but also inside the plug-in access to external space variables, such as jquery,$
Common plug-in forms are:
(function () {/* Here is Implementation code */}) ();
Well, it can be.
;(function ($) {var foo;//local variable var bar=function () {/* * functions inside the anonymous function can access Foo, even if you call bar outside of the anonymous function, you can also access Foo, But the direct access to Foo outside of the anonymous function is */$. bar=bar;//allows the inner function bar () of an anonymous function to escape to the globally accessible space so that the internal function bar ()}) (JQuery) can be accessed through Jquery.bar ();
Writing jquery Plugins