[ES6] Proxy & Reflect
2023-09-14 09:00:50 时间
Proxy and Reflect API works nicely together.
About how to use Proxy, check this post.
Let's see about Reflect API:
const obj = {name: "foo"}; console.log(Reflect.get(obj, "name")); // "foo"
For proxy and Reflect, their API is really similar:
const target = {name: "foo"}; const handler = { get: function(target, key){ console.log("Accessd key", key); return Reflect.get(target, key); // using Reflect to get the value }, set: function(target, key, value){ console.log('Update key', key, "to", value); Reflect.set(target, key, value); // using Reflect to set the value } }; function logAccessToProperties(obj) { return new Proxy(obj, handler); } const l = logAccessToProperties(target); console.log(l.name); //foo l.age = 23 console.log(l.age ); //23
相关文章
- es6 模板字符串_json字符串转成标准格式输出
- ES6—class类详细教程(下)
- ES6基础之——继承extends
- ES6 Class类详解(万字长文,值得收藏)
- babel转换es6_ideamaven依赖配置
- babel es6转es5原理_vue用es6还是es5
- webpack-ES6转ES5[通俗易懂]
- 每天3分钟,重学ES6-ES12(六)ES7 ES8 新增内容
- 每天3分钟,重学ES6-ES12(七)ES10 新增内容
- ES6-异步遍历器(三)
- ES6之数组的实列方法一
- es6扩展运算符、concat方法合并多个数组
- JS模块化—CJS&AMD&CMD&ES6-前端面试知识点查漏补缺_2023-03-13
- ES6 spread operator 展开运算符详解编程语言
- ES6 rest parameter详解编程语言