【问题标题】:JS delegating/extending aleady existing functionJS委托/扩展aleady现有功能
【发布时间】:2015-08-04 07:58:01
【问题描述】:

如何将代码添加到保留旧功能的函数中

SomeFunction = function () {
    someOtherFunction();
    return this.apply(this, arguments);
};

【问题讨论】:

    标签: javascript delegates


    【解决方案1】:

    就这样

    var delegate = functionToBeDelegated;
    functionToBeDelegated = function () {
    
        //
        // Add functionality to the function
        //
    
        // run the old version of the function in native scope
        return delegate.apply(this, arguments);
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-06
      • 1970-01-01
      • 2015-03-22
      • 1970-01-01
      • 1970-01-01
      • 2015-09-03
      • 2017-07-02
      • 2021-09-20
      相关资源
      最近更新 更多