-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
49 lines (42 loc) · 1.2 KB
/
Copy pathindex.html
File metadata and controls
49 lines (42 loc) · 1.2 KB
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
<!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>
<script>
// const state = {
// count: 0,
// };
// const useState = () => {
// return [
// state.count,
// (v) => {
// state.count = v;
// },
// ];
// };
// const data = useState();
// setTimeout(() => {
// console.log(data[0], data, state, "count>>>");
// }, 3000);
// data[1](10);
/**
* 这里记录一下为什么useEffect延时几秒执行,获取的不是state最新值的问题
* **/
let obj = {
count: 1,
};
// 这里把obj.count这个值赋值到了arr[0]里面,后续修改obj.count的时候也不会影响arr[0]
// 因为他只是值赋值过去了,没有任何的引用关系
// 就相当于创建了一个新变量,给这个新变量赋值
const arr = [obj.count];
setTimeout(() => {
console.log(arr[0]);
}, 3000);
obj.count = 10;
</script>
</body>
</html>