Proxy can intercept operations such as reading, modifying and traversing objects. This polyfill only supports get and set.
Implemented by defineProperty and VBScript.
Object.defineProperty in lower version browsers is implemented with __defineGetter__ and __defineSetter__.
So the attribute of target must be defined first.
Calling example:
var person = {
name: "张三"
};
var proxy = new Proxy(person, {
set:function(target, property, value) {
if(property in target) {
alert("set "+property+":"+value);
}else{
throw "Property \"" + property + "\" does not exist.";
}
}
});
proxy.name="李四";
Code https://github.com/linsk1998/skyjs/blob/master/scenario/proxy/proxy.js
Demo http://raw.githack.com/linsk1998/skyjs/master/scenario/proxy/index.html