引言
es5 给提供了对象属性劫持的方法 Object.definedProperty,es6 同样通过 proxy 给我们带来了类似的功能,而且性能更好
Object.defineProperty (es5)
- configurable 可配置
- enumerable 可枚举
- writeable 可写入
- value
- get
- set
1 | var tmp = "123"; |
1 | var obj = {}; |
1 | var obj = {}; |
Proxy 拦截器
- target 劫持对象
- propkey 操作的属性
- receiver proxy 的实例
1 | var obj = { |
通过 proxy 实现对象的私有属性
1 | const obj = { |
I'm so cute. Please give me money.
- Post link: https://blog.gaocaipeng.com/2020/03/12/vr3dmp/
- Copyright Notice: All articles in this blog are licensed under unless otherwise stated.