给对象动态增加职责的方式称为装饰者模式。

Function.prototype.before = function(beforefn){

      var _self = this;

      return function(){

             beforefn.apply(this,arguments);

             return _self.apply(this,arguments);

      }

}

 

Function.prototype.after = function(afterfn){

      var _self = this;

      return function(){

             var ret = _self.apply(this,arguments);

             afterfn.apply(this,arguments);

             return ret;

      }

}

相关文章:

  • 2021-12-11
  • 2021-06-08
  • 2021-11-11
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-19
  • 2021-06-07
  • 2021-09-30
  • 2021-08-13
  • 2022-12-23
  • 2022-12-23
  • 2021-07-28
相关资源
相似解决方案