Reflect的作用,target,property,value,receiver代表啥

1.真的proxy

复制代码
let target ={name:'张三'}
let handler = {
  get(target,property,receiver){
    console.log(1,target,2,property,3,receiver)
    return Reflect.get(target,property,receiver)
  },
  set(target,property,value,receiver){
    console.log('a',target,'b',property,'c',value,'d',receiver)
    return Reflect.set(target,property,value,receiver)
  }
}
let proxy = new Proxy(target,handler)
console.log(proxy.name)
proxy.name = '李四'
// console.log(proxy.name)

以上代码用浏览器控制台运行下如下

可知target,property,value,receiver的值

不知道为啥这里的target换成多层的对象就不起作用了

复制代码
let target ={name:'张三',info:{age:18,sex:'男'}}
console.log(proxy.info.sex)
proxy.info.sex = '女'

2.自己写的proxy

很明显这里的reflect.get被return targetkey替代,

reflect.set被 '=' 替代

说明了reflect在proxy的作用

复制代码
let handler = {
  get(target, key, receiver) {
    console.log(1, target, 2, key, 3, receiver)
    return target[key];
  },
  set(target, key, value, receiver) {
    console.log('a', target, 'b', key, 'c', value, 'd', receiver)
    target[key] = value;
    return true;
  },
};
let target ={name:'张三'}
let proxy = new Proxy(target, handler);
console.log(proxy.name)
proxy.name = '李四'
console.log(proxy.name)
相关推荐
ym hyd 1115 小时前
试题库管理系统源码 Java+SpringBoot+Vue3 前后分离
java·vue.js·spring boot·毕设
迅猛龙办公室5 小时前
Python输出当前计算机的系统日期和时间
开发语言·前端·python
小狼154546 小时前
浏览器扩展脚本为什么有时候不生效:注入时机、iframe 和单页路由,多多开票助手
前端·chrome
じòぴé南冸じょうげん6 小时前
油猴脚本突然发现变成灰色了,无法使用?页面不生效?刷新页面没反应?
前端
Csvn8 小时前
组合式 API(Composition API)
前端
火柴就是我9 小时前
Android 打包报错 25.0.3
android·前端
BD_Marathon9 小时前
消息对象中字段的说明
java·前端·python
八荒启·交互动画9 小时前
Web特效025—用 Canvas 2D 做Web特效的定义与边界:这支画笔能做到哪一步
前端·webgl·网页特效·八荒启-交互动画·八荒启
Ai-_Man9 小时前
您您这可以把Dola的多个会话比如说。左侧的多个会话一次性导出吗?不是单条会话里面的多次会对话。用AI导出鸭,答案是可以的
开发语言·前端·人工智能·小程序
excel9 小时前
Nuxt 中使用 useHead 优化 SEO 与 GEO
前端