jQuery object copy
If you want to copy (merge) an object to another object, you can use the $.extend() method at this time
grammar:
$.extend([deep],target,object1,[objectN])
- deep: If set to true for deep copy, the default is false shallow copy
- target: Object type target object, member attributes of other objects will be attached to this object
- object1: Optional, the first object of the Object type to be merged.
- objectN: Optional, the Nth merged object of the Object type.
- Shallow copy is to copy the address in the complex data type of the copied object to the target object. Modifying the target object will affect the copied object
- Deep copy, add true in front, complete clone (the copied object, not the address), modifying the target object will not affect the copied object
var targetObj = {
};
var obj = {
id:1,
name:"andy"
}
//$.extend(target, obj);
$.extend(targetObj, obj);
note:
- If only one parameter is specified for $.extend(), it means that the target parameter is omitted. At this point, the target is the jQuery object itself. through ways. We can add new functions to the global object jQuery
- If multiple objects have the same properties, the latter will override the former's property value