-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo3.html
102 lines (89 loc) · 2.86 KB
/
demo3.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
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
92
93
94
95
96
97
98
99
100
101
102
<!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>
</body>
<script>
// function stringify(obj) {
// let type = typeof obj;
// if (type !== "object" || type === null) {
// if (/string|undefined|function/.test(type)) {
// obj = '"' + obj + '"';
// }
// return String(obj);
// } else {
// let json = [];
// let isArr = Array.isArray(obj);
// for (let k in obj) {
// let v = obj[k];
// let type = typeof v;
// if (/string|undefined|function/.test(type)) {
// v = '"' + v + '"';
// } else if (type === "object") {
// v = stringify(v);
// }
// json.push((isArr ? "" : '"' + k + '":') + String(v));
// }
// let arrStr = "[" + String(json) + "]";
// let objStr = "{" + String(json) + "}";
// return isArr ? arrStr : objStr;
// }
// }
function stringify(target) {
// write your code
let type = typeof target;
if (type !== "object" || type === null) {
if (/string|undefined|function/.test(type)) {
target = '"' + target + '"';
}
return String(target);
} else {
let json = [];
let isArr = Array.isArray(target);
for (let key in target) {
let value = target[key];
let type = typeof value;
if (/string|undefined|function/.test(type)) {
value = '"' + value + '"';
} else if (type === "object") {
value = stringify(value)
}
json.push((isArr ? "" : '"' + key + '":') + String(value))
}
let arrStr = "[" + String(json) + "]";
let objStr = "{" + String(json) + "}";
return isArr ? arrStr : objStr
}
}
console.log(stringify(() => void 0))
console.log(stringify(true))
console.log(stringify(/\w/))
console.log(stringify(12345))
console.log(stringify('hello world'))
console.log(stringify([1, 2, 3, 4, { a: { value: [true, 'js', 1, null, undefined] } }]))
// console.log(JSON.stringify(() => void 0))
// console.log(JSON.stringify(true))
// console.log(JSON.stringify(/\w/))
// console.log(JSON.stringify(12345))
// console.log(JSON.stringify('hello world'))
// console.log(JSON.stringify([1, 2, 3, 4, { a: { value: [true, 'js', 1, null, undefined] } }]))
// 常见的HTTP状态码
// js异步发展
// 简述下eventloop
// 网页性能优化
// 1. React在项目中使用多久
// 2. React生命周期
// 3. React组件与组件如何通讯
// 4. class组件与函数组件有什么不同
// 5. useEffect和useLayoutEffect区别
// 5. React性能优化
// 6. 了解过diff过程吗?fiber算法?
// 7. 了解过webpack mode(毛得)production 和 区别?
// 8. 简单描述下tree shaking
// 9. webpack热更新原理
</script>
</html>