-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (30 loc) · 917 Bytes
/
index.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
const obj1 = { name: 'leo' }
const obj2 = { o: obj1 }
const proxy = new Proxy(obj2, {
get(target, key, receiver) {
console.log('root', target, key, receiver)
const res = Reflect.get(target, key, receiver)
return new Proxy(res, {
get(target, key, receiver) {
console.log(target, key, receiver)
return Reflect.get(target, key, receiver)
},
set(target, key, value, receiver) {
console.log(target, key, '@@@', value, receiver)
return Reflect.set(target, key, value, receiver)
}
})
},
set(target, key, value, receiver) {
console.log('root', target, key, '@@@', value, receiver)
return Reflect.set(target, key, value, receiver)
}
})
// console.log(proxy.o)
// console.log(proxy.o.name)
// proxy.o = 'pp'
// proxy.o.name = 'git'
// console.log(proxy.o.name)
// proxy.b = { bb: 'kk' }
// proxy.b.bb = 'oo'
console.log(proxy.prototype)