Home > Article > Web Front-end > A brief discussion on the 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.
$.extend( target [, object1 ] [, objectN ] )
Indicates whether Deep merge
##$.extend( [deep ], target, object1 [, objectN ] )
Parameter | Description |
---|---|
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. | |
Object type Target object, the member properties of other objects will be attached to this object. | |
Object type The first object to be merged. | |
Object type The Nth merged object. |
<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>
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!