📜  javascript 中间件 getter 和 setter - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:28.633000             🧑  作者: Mango

代码示例1
// Use a Proxy object with getter/setter traps instead
const obj = {};

const proxObj = new Proxy(obj, {
  get(obj, prop) {
    console.log(`Getting ${prop} from `, obj));
    return obj[prop];
  },
  set(obj, prop, newValue) {
    console.log(`Setting ${prop} with value ${newValue} on `, obj));
    return obj[prop] = newValue;
  },
});