Home > Web Front-end > JS Tutorial > jQuery $.extend() usage summary_jquery

jQuery $.extend() usage summary_jquery

WBOY
Release: 2016-05-16 16:44:40
Original
1073 people have browsed it

jQuery provides two methods for developing plug-ins, namely:
jQuery.fn.extend(object);

jQuery.extend(object);
jQuery.extend(object); Extend the jQuery class itself. Add new methods to the class.
jQuery.fn.extend(object); Add methods to jQuery objects. This should be easy to understand. Give an example.

Copy code The code is as follows:






new soul


new soul


new soul


new soul








Okay, you also saw a little usage of $.extend() above.

1. Merge multiple objects.

What is used here is the function of nesting multiple objects of $.extend().

The so-called nesting of multiple objects is somewhat similar to the operation of merging arrays.

But here are the objects. Give examples.
Copy code The code is as follows:

//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 attribute of Css1 is overwritten and the weight attribute of Css2 is inherited
// Css1 = {size: "12px", style: "oblique", weight: "bolder"}


2. Deeply nested objects.
Copy code The code is as follows:

jQuery.extend(
{ name: "John", location: { city: "Boston" } },
{ last: "Resig", location: { state: "MA" } }
);
// Result:
// => { name: “John”, last: “Resig”, location: { state: “MA” } }
// New and more in-depth .extend()
jQuery.extend( true,
{ name: "John", location: { city: "Boston" } },
{ last: "Resig", location: { state: "MA" } }
);
// result
// => { name: "John", last: "Resig",
// location: { city: "Boston" , state: "MA" } }


3. You can add static methods to jQuery.
Copy code The code is as follows:










Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template