JQuery $.extend () usage

Source: Internet
Author: User
Summary of $.extend () usage.
jquery has two methods for developing Plug-ins, respectively:
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); Add methods to the JQuery object. This should be very well understood. Give an example.

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

OK, so you've seen a little bit of $.extend ().


1. Merge multiple objects.


This is the function of nesting multiple objects for $.extend ().

Nesting multiple objects is a bit like an array-merging operation.

But this is the object. An example is provided.

<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 overwritten and inherits Css2 weight attribute
//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 a static method 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.