const target = {};
// const obj = {};
const handler = {
get: function(target, key, receiver) {
console.log(`geting${key}`);
return Reflect.get(target, key, receiver);
}
// set: function(target, key, value, receiver) {
// console.log(`seting${key}`);
// return Reflect.set(target, key, value, receiver);
// }
};
const obj = new Proxy(target, handler);
// Object.setPrototypeOf(obj, proxy);
obj.a = 1;
obj.b = 2;
console.log(obj.a);
console.log(obj.b);
// console.log(target.a);
// console.log(target.b);
网友评论