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);



相关文章:

  • 2021-05-12
  • 2021-08-29
  • 2021-08-12
  • 2022-12-23
  • 2022-12-23
  • 2021-12-26
  • 2021-12-26
猜你喜欢
  • 2022-12-23
  • 2021-11-25
  • 2021-07-08
  • 2022-12-23
  • 2022-12-23
  • 2021-07-20
  • 2022-12-23
相关资源
相似解决方案