How jquery customizes plugins (extended instances/static methods)

Source: Internet
Author: User
Tags instance method

1, jquery plug-in type:
1), the plug-in that encapsulates the object method (equivalent to an instance method) (using $.fn.extend ({"Method name": function (parameter) {//Method body}}))
2), the plug-in that encapsulates the global function (equivalent to $ static method)
3), selector plug-in

2, the attention point
1), plug-in file naming specification: jquery. [Plugin name].js
2), object method attached to the Jquery.fn object on a static method attached to the JQuery object itself
3), inside the plug-in, this refers to the jquery object that the selector gets, not the DOM object
4), can traverse all elements through This.each ()
5), plug-ins should return a jquery object to ensure chained programming unless the plug-in needs to return some specific values

Custom instance plug-ins
$.fn.extend ({

"Color": function (value) {
if (value==undefined) {return this.css ("Color");}
Else
{
return this.css ("Color", value);
}
}
});

Customizing the global method plug-in
$.extend ({"SayHello": function (v) {
Alert ("Hello,my Name is" +v);
}});

Another common use of $.extend is to merge other objects onto the target object. The first parameter True indicates a deep copy
$.extend (True, target object, Object1);

How jquery customizes plugins (extended instances/static methods)

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.