7.js模式-装饰者模式

1. 装饰者模式

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

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;

      }

}

原文地址:https://www.cnblogs.com/SLchuck/p/4869720.html