Home > Web Front-end > JS Tutorial > body text

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

小云云
Release: 2018-01-23 09:15:07
Original
1694 people have browsed it

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 
包含额外的属性合并到第一个参数。
Copy after login

$.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覆盖
Copy after login

$.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}
Copy after login
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!

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