簡體   English   中英

如何擺脫這個函數中的“with()”?

[英]how do I get rid of “with()” in this function?

因為不推薦使用with()函數,所以我想在我的代碼中刪除它。

我怎么能在這個特定的功能中做到這一點?

原始代碼:

(function(a,b){
for(a in b=a.prototype)with({d:b[a]})b[a]=function(c){d.apply(this,arguments);return this}
})(Element);

格式化代碼供參考:

(function(a, b) {
    for (a in b = a.prototype)
        with({ d: b[a] })
            b[a] = function(c) {
                d.apply(this, arguments);
                return this
            }
})(Element);​

其原因with正在使用是關閉以上的值b[a]的函數內,正確的替換是具有閉合:

(function(a, b) {
    for (a in b = a.prototype)
        (function (d) { //this line used to be: with({ d:b[a] })
            b[a] = function(c) {
                d.apply(this, arguments);
                return this
            }
        }(b[a])); //this is where `d` is set
})(Element);​

暫無
暫無

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

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