zoukankan      html  css  js  c++  java
  • 装饰者模式AOP

    Function.prototype.after=function(fn){
      var _this=this;
      return function(){
          var _q=_this.apply(this, arguments);
          fn.apply(this, arguments);
          return _q;
      };
    };
    
    Function.prototype.before= function(fn){
      var _this=this;
      return function(){
          fn.apply(this, arguments);
          return _this.apply(this, arguments);
      };
    };
    
    function qq(){
      alert('qqq');
    }
    var q1=qq.before(function(){
        alert(1);
      }).after(function(){
        alert(2);
      }).before(function(){
        alert(3);
      });
    
    q1();
    
    ----------------------------------------------------------------------------
    
    var before = function( Fn , beforeFn ){
      return function(){
        beforeFn.apply(this,arguments);
        Fn.apply(this,arguments);
      };
    };
    var a = before(
      function(){ alert(1); },
      function(){ alert(2); }
    );
    
    a = before(a,function(){alert(3);});
    a = before(a,function(){alert(4);});
    a = before(a,function(){alert(5);});
    a = before(a,function(){alert(6);});
    a();

     摘自JavaScript设计模式与开发实践

  • 相关阅读:
    Begin Again
    hadoop集群启动start-dfs.sh有节点datanode启动不了问题
    centos中python更新后yum不可用问题
    浏览器无法访问hdfs界面问题
    数据的统计分析与描述
    插值与拟合
    层次分析法
    四种规划-数学建模
    Hive深入使用
    Hadoop-Hive
  • 原文地址:https://www.cnblogs.com/cszdsb/p/6610445.html
Copyright © 2011-2022 走看看