Open tTdly-Old opened 1 year ago
vue 通过代理给对象进行增强,之后无论是访问代理对象还是访问源对象都会有相同的属性,但是访问源对象并不会用上代理的增强属性。 Proxy代理生成的对象没有原型,其原型为undefined。 如果想要重写代理中的捕获器的行为需要使用Reflect来进行重写。
const target = { foo: 'bar', baz: 'qux' }; const handler = { get(trapTarget, poperty, reciver) { let decoration = ''; if (poperty === 'foo') { decoration = '!!!'; } return Reflect.get(...arguments) + decoration; } } const proxy = new Proxy(target, handler); console.log(proxy.foo); console.log(proxy.baz);
接收:
vue 通过代理给对象进行增强,之后无论是访问代理对象还是访问源对象都会有相同的属性,但是访问源对象并不会用上代理的增强属性。 Proxy代理生成的对象没有原型,其原型为undefined。 如果想要重写代理中的捕获器的行为需要使用Reflect来进行重写。
代理捕获方法
get()
接收:
set()
接收:
has()
接收:
defineProperty()
接收: