java中很多框架支持 apo 的注入, js中也可以类似的进行实现
主要是通过扩展js中方法的老祖 Function 对象来进行实现.

Function.prototype.after = function(foo) {
    const thiz = this;
    return function(...args) {
         thiz.apply(thiz, args);
         foo.apply(thiz, args);
 
    }
}
//test
function test(param) {
    console.log("do");
}
function doAfter(param) {
    console.log("doAfter");
}
const doWithAfter = test.after(doAfter);

before 也是类似的. 另外还可以通过 Proxy 进行实现.

相关文章:

  • 2021-07-08
  • 2022-12-23
  • 2022-02-09
  • 2022-12-23
  • 2021-05-12
  • 2022-12-23
  • 2021-11-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-07
  • 2022-12-23
  • 2021-10-21
  • 2022-02-18
相关资源
相似解决方案