tTdly-Old / ttdly-old.github.io

博客站点
GNU General Public License v3.0
0 stars 0 forks source link

给个面子过了吧 #20

Open tTdly-Old opened 1 year ago

tTdly-Old commented 1 year ago

title: "测试文章" date: "2023-03-12T06:45:08Z"

"vue<span class=\"i-logos-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);

代理捕获方法

get()

接收: