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
|
const obj = { name: '刘逍', age: 20 } const p = new Proxy(obj, { get(target, propName) { console.log(`有人读取p对象里的${propName}属性`); return Reflect.get(target, propName) }, set(target, propName, value) { console.log(`有人修改了p对象里的${propName}属性,值为${value},需要去修改视图`); Reflect.set(target, propName, value) }, deleteProperty(target, propName) { console.log(`有人删除了p对象里的${propName}属性,需要去修改视图`); return Reflect.deleteProperty(target, propName) } })
|