JQuery $.extend () usage

Source: Internet
Author: User

$.extend () Usage Summary.
jquery has two methods for developing plug-ins, namely:
JQuery.fn.extend (object);

Jquery.extend (object);

Jquery.extend (object); To extend the JQuery class itself. Adds a new method to the class.
JQuery.fn.extend (object); Adds a method to a jquery object. This should be very well understood. Let me give you an example.

< Span style= "FONT-SIZE:18PX;" >

OK, so you see a little bit of $.extend () usage.


1. Merge multiple objects.


This is where $.extend () is used to nest multiple objects.

The so-called nested multiple objects, a bit similar to the merging of arrays of operations.

But here is the object. An example is described.

<span style= "FONT-SIZE:18PX;" >//usage: jquery.extend (obj1,obj2,obj3,..) var css1={size: "10px", Style: "Oblique"}var css2={size: "12px", Style: "Oblique", Weight: "Bolder"}$.jquery.extend (Css1 , CSS2)//Result: The Size property of Css1 is overridden and inherits the weight attribute of Css2//Css1 = {size: "12px", Style: "Oblique", Weight: "Bolder"}</span>


2. Deep nested objects.


<span style= "FONT-SIZE:18PX;"  >  jquery.extend (       {name: ' John ', Location: ' City: ' Boston '}},       {last: ' Resig ', location: ' {state: ' MA '} }     );      Result:      //+ = {name: ' John ', Last: ' Resig ', location: {state: ' MA '}}//New deeper. Extend ()     Jquery.extend (True     {name: ' John ', location: {city: ' Boston '}},       {last: ' Resig ', location: {state: ' MA '}}    );    Result     //+ = {name: ' John ', Last: ' Resig ',    //location      : {city: ' Boston ', State: ' MA '}}  </span >

3. You can add static methods to jquery.


<span style= "FONT-SIZE:18PX;" >
Best Wishes

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.