Compile the jQuery plug-in and jquery plug-in

Source: Internet
Author: User

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 );



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.