-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeepCopy.js
91 lines (79 loc) · 1.96 KB
/
deepCopy.js
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
let obj1 = {
a: {
b: 1
}
}
function deepClone(obj) {
let cloneObj = {};
for (let key in obj) {
if (typeof obj[key] === 'object') {
cloneObj[key] = deepClone(obj[key]);
} else {
cloneObj[key] = obj[key];
}
}
return cloneObj;
}
var total = [1, 2, 3];
var a = Object.prototype.toString.call(total);
console.log(a);
var b = Array.isArray(total);
console.log(b);
console.log(typeof (undefined));
console.log(typeof (null));
console.log(typeof (NaN));
console.log(Number.MAX_SAFE_INTEGER);
var b = ["1", "2", "3"].map(parseInt);
console.log(b);
function New(func) {
let res = {};
if (func.prototype !== null) {
res.__proto__ = func.prototype;
}
//这里是
var ret = func.apply(res, Array.prototype.slice.call(arguments, 1));
if (typeof ret === "null" || typeof ret === "function" || typeof ret === "null") {
return ret;
}
return res;
}
function instance(left, right) {
var leftVal = left.__proto__;
var rightVal = rightVal.prototype;
while (leftVal !== null) {
if (leftVal === rightVal) return true;
leftVal = leftVal.__proto__;
rightVal = rightVal.prototype;
}
return false;
}
//防抖
function debounce(fn, wait) {
let timer = null;
return function () {
var context = this;
var args = arguments;
if (timer) {
clearTimeout(timer);
timer = null;
}
timer = setTimeout(function () {
fn.apply(context, args);
}, wait)
}
}
//节流
function throttle(fn, wait) {
let timer = null;
return function () {
var context = this;
var args = arguments;
if (timer) {
return;
}
timer = setTimeout(function () {
fn.apply(context, args);
timer = null;
}, wait);
}
}