jQuery $. extend shallow copy and deep copy

  • 2021-08-03 08:27:11
  • OfStack

jQuery $. extend shallow copy and deep copy


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

 deep 
 Type : Boolean 
 If it is true , merge into recursion (also known as deep copy). 
 target 
 Type : Object 
 Object extension. This will receive new attributes. 
 object1 
 Type : Object 
1 Object that contains additional attributes merged into the 1 Parameters. 
objectN 
 Type : Object 
 Include additional attributes and merge them into the 1 Parameters. 

Shallow copy of $. extend:


var obj1 = {name:xx,age:18,sex:man};
var obj2 = {name:cc,age:18};
$.extend(obj1,obj2);
obj1----->{name:cc,age:18} // Be obj2 Covering 

$. extend Deep Copy:


var obj1 = {name:xx,age:18,sex:man};
var obj2 = {name:cc,age:18};
$.extend(true,obj1,obj2);
obj1----->{name:cc,age:18 , sex:man}

Thank you for reading, hope to help everyone, thank you for your support to this site!


Related articles: