-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.html
52 lines (42 loc) · 1.04 KB
/
index.html
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
interview
</body>
<script>
// Object.prototype.myBind = function (context, ...arg) {
// if (typeof this !== 'function') {
// throw TypeError('holp caller is function')
// }
// let obj = context || window;
// return (...arg2) => {
// this.call(obj, ...arg, ...arg2)
// }
// }
// 默写一遍深度克隆
// 思路:
// 1 原始对象类
// 2 需要循环遍历的
// 只记忆下面这个
function clone(target, map = new Map()) {
if(typeof target === 'object') {
let cloneTarget = Array.isArray(target) ? [] : {};
if(map.get(target)) {
return map.get(target)
}
map.set(target, cloneTarget);
for (const key in target) {
cloneTarget[key] = clone(target[key], map)
}
return cloneTarget
} else {
return target;
}
}
</script>
</html>