Jquery---$.fn---jQuery.fn.extend

Source: Internet
Author: User

(1) How to develop plug-ins:

Jquery.extend (object) is the extension of the jquery class itself, adding new methods to the class.

JQuery.fn.extend (object) Adds a method to a jquery object and adds a member function (Jquery.fn = jquery.prototype) to the jquery class.

(2) Specific wording: an extension of the notation is to call $.ab= ({}) when $.ab.add ()

$.extend ({

Sub:function (A, b) {returna-b;}

Add:function (A, b) {returna+b;}

});

$.fn.extend ({

Sub:function (A, b) {returna-b;}

      Add:function (A, b) {returna+b;}

});

$.add (2,5);

(3) $.extend can also be used to merge objects:

Obj1 = {name: "John", Location: {City: "Boston"}};

Obj2 = {Last: ' Resig ', location: {state: ' MA '}};

Jquery.extend (True,obj1, obj2);

Results:

{name: ' John ', Last: ' Resig ', location: ' {state: ' MA '}}

True indicates a deep copy, changing the value of the OBJ2 does not affect the value of obj1, and if a shallow copy is made, changing the object value in the OBJ2 causes the object value in the Obj1 to change.


Jquery---$.fn---jQuery.fn.extend

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.