-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeepClone.html
More file actions
38 lines (31 loc) · 865 Bytes
/
deepClone.html
File metadata and controls
38 lines (31 loc) · 865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script type="text/javascript">
//深度克隆的函数实现
function deepClone(origin, target) {
var target = target || {},
toStr = Object.prototype.toString,
arrStr = "[object Array]";
for(var prop in origin) {
if(origin.hasOwnProperty(prop)) {
if(origin[prop] !== "null" && typeof (origin[prop] == "object")) {
if(toStr.call(origin[prop]) == arrStr) {
target[prop] = [];
}else{
target[prop] = {};
}
deepClone(origin[prop], target[prop]);
}else{
target[prop] = origin[prop];
}
}
}
}
</script>
</body>
</html>