Proxy

let obj = new Proxy({}, {
  get(target, key, receiver) {
    console.log(`getting ${key}`);
    return Reflect.get(target, key, receiver);
  },
  set(target, key, value, receiver) {
    console.log(`setting ${key}`);
    return Reflect.set(target, key, value, receiver);
  }
});

obj.count = 1; // setting count
obj.count; // getting count
// 将 Proxy 设置为 obj 的对象,可以在 obj 对象上调用
let obj = {
  proxy: new Proxy({}, {
    get(target, key, receiver) {
      return Reflect.get(target, key, receiver);
    },
    set(target, key, value, receiver) {
      return Reflect.set(target, key, value, receiver);
    },
  }),
};
// 作为其他对象的原型对象