繁体   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