簡體   English   中英

JS委托/擴展aleady現有功能

[英]JS delegating/extending aleady existing function

如何向功能添加代碼以保留其舊功能

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

就這樣

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM