var proxy = new Proxy(target,handler);
new Proxy({},{
get: function(target,property) {
return 35;
}
});
proxy.time // 35
proxy.name 35
proxy.title 35
var target = {};
var handler = Proxy(target,handler);
proxy.a = 'b';
target.a "b"
{
get: if (name === 'prototype') return Object.prototype;
return 'Hello,' + name;
},apply: function(target,thisBinding,args) { return args[0]; },1)">construct: return args[1]; }
};
var fproxy = new Proxy((x,y) {
return x + y;
},handler);
fproxy(1,2); 1
new fproxy(1,1)"> 2
fproxy.prototype; Object.prototype
fproxy.foo; 'Hello,foo'
老写法
try {
Object.defineProperty(target,property,attributes);
success
} catch (e) {
failure
}
新写法
if (Reflect.defineProperty(target,attributes)) {
else {
failure
}
老写法
'assign' in Object true
新写法
Reflect.has(Object,'assign') true
失败时抛出错误
Object.defineProperty(obj,desc);
失败时返回false
Reflect.defineProperty(obj,desc);