-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcodeDemo.html
61 lines (53 loc) · 1.44 KB
/
codeDemo.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
<!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>
// var a = 10;
// function a() {
// a = 20;
// console.log(a)
// }
// a() // 返回报错 a is not function
// [1,2,3].map(parseInt) // 1,NaN,NaN map(parseInt(item,idx)) 1,0 2,1 3,2 0默认是十进制
// vue2.0 双向绑定的核心
let book = {}
Object.defineProperty(book, "name", {
set: function (value) {
if (value !== book['name']) {
console.log('price属性被修改了')
book['name'] = value
}
},
get: function () {
console.log('price属性被读取了')
return book['name']
}
})
// vue3 双向绑定
let student = {
name: '1'
}
let handle = {
get: function (target, property) {
console.log('属性读取了')
return target[property]
},
set: function (target, property, value) {
console.log('属性修改了')
let res = Reflect.set(target, property, value);
// var watchers = that.deps[key];
// watchers.map(item => {
// item.update();
// });
return res;
}
}
let proxy = new Proxy(student, handle)
</script>
</html>