Home  >  Article  >  Web Front-end  >  Analysis of jQuery's $.extend shallow copy and deep copy examples

Analysis of jQuery's $.extend shallow copy and deep copy examples

小云云
小云云Original
2018-01-23 09:15:071682browse

What are jQuery's $.extend shallow copy and deep copy? This article mainly introduces the relevant information of jQuery's $.extend shallow copy and deep copy. Friends who need it can refer to it. I hope it can help everyone.

jQuery’s $.extend shallow copy and deep copy


$.extend( [deep ], target, object1 [, objectN ] );
 deep 
类型: Boolean 
如果是true,合并成为递归(又叫做深拷贝)。
 target 
类型: Object 
对象扩展。这将接收新的属性。
 object1 
类型: Object 
一个对象,它包含额外的属性合并到第一个参数。
objectN 
类型: Object 
包含额外的属性合并到第一个参数。

$.extend shallow copy:


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

$.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}

Related recommendations:


jQuery $.extend() usage summary

Js-$.extend extension method makes method parameters more flexible_javascript skills

Usage example of $.extend() in jQuery_jquery

The above is the detailed content of Analysis of jQuery's $.extend shallow copy and deep copy examples. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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