A brief discussion on the extend function in jquery

零到壹度
Release: 2018-03-20 15:22:31
Original
1400 people have browsed it

This article mainly talks about the specific steps and related operation skills of the extend function in jquery. Friends in need can refer to it. I hope it can help everyone.

extend function in jquery

jQuery.extend() function is used to extend one or more The object's contents are merged into the target object.

Note:1. If only one parameter is specified for $.extend(), it means that the parameter target is omitted. At this point, the target is the jQuery object itself. In this way we can add new functions to the global object jQuery.

2. If multiple objects have the same properties, the latter will overwrite the former’s property values.

Syntax

$.extend( target [, object1 ] [, objectN ] )
Indicates whether Deep merge

##$.extend( [deep ], target, object1 [, objectN ] )

##deep Optional. Boolean type indicates whether to merge objects deeply. The default is false. If this value is true, and a property with the same name in multiple objects is also an object, the properties of the "property object" will also be merged. target Object type Target object, the member properties of other objects will be attached to this object. object1 Object type The first object to be merged. objectN Object type The Nth merged object.
Parameter Description
eg:

var resultA=$.extend({},{name:"A",age:21},{name:"B",sex:"Boy"})
resultA={name:"B",age:21,sex:"Boy"}var resultB=$.extend( true, {},
{ name: "A", location: {city: "beijing",county:"us"} },
{ last: "B", location: {state: "shanghai",county:"China"} } );
resultB{name:"A",last:"B",location{city:"beijing",state:"shanghai",county:"China"}}var resultC=$.extend( false, {},
{ name: "A", location: {city: "beijing",county:"us"} },
{ last: "B", location: {state: "shanghai",county:"China"} } );
resultC = {name:"A",last:"B",location:{state:"shanghai",county:"China"}}
Copy after login

The above is the detailed content of A brief discussion on the extend function in jquery. For more information, please follow other related articles on the PHP Chinese website!

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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!