Writing jquery Plugins

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.