js代理并重写一个已有的方法的神奇办法~~~

90 阅读1分钟
let originalMethod = () => {
  console.log('原始方法被调用');
}

const proxyHandler = {
  apply: function(target, thisArg, args) {
    console.log('代理方法被调用');
    target(); // 执行原始方法
  }
};

const proxyFunction = new Proxy(originalMethod, proxyHandler);
originalMethod = proxyFunction
originalMethod();