Home > Web Front-end > JS Tutorial > A brief discussion on the extend function in jquery

A brief discussion on the extend function in jquery

零到壹度
Release: 2018-03-20 15:22:31
Original
1504 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 ] )

##deepOptional. 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. targetObject type Target object, the member properties of other objects will be attached to this object. object1Object type The first object to be merged. objectNObject type The Nth merged object.
Parameter Description
eg:

<span style="font-size: 14px;">var resultA=$.extend({},{name:"A",age:21},{name:"B",sex:"Boy"})<br/>resultA={name:"B",age:21,sex:"Boy"}var resultB=$.extend( true, {}, <br/>{ name: "A", location: {city: "beijing",county:"us"} }, <br/>{ last: "B", location: {state: "shanghai",county:"China"} } );<br/>resultB{name:"A",last:"B",location{city:"beijing",state:"shanghai",county:"China"}}var resultC=$.extend( false, {}, <br/>{ name: "A", location: {city: "beijing",county:"us"} }, <br/>{ last: "B", location: {state: "shanghai",county:"China"} } );<br/>resultC = {name:"A",last:"B",location:{state:"shanghai",county:"China"}}</span>
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template