wil*_*alo 2 javascript with-statement
由于该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);
Run Code Online (Sandbox Code Playgroud)
(function(a, b) {
for (a in b = a.prototype)
with({ d: b[a] })
b[a] = function(c) {
d.apply(this, arguments);
return this
}
})(Element);?
Run Code Online (Sandbox Code Playgroud)
使用的原因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);?
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
133 次 |
| 最近记录: |