Reputation: 2506
since the with()
function is deprecated, I want to get rid of it in my code.
How can I do it in this particular function?
(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);
Upvotes: 2
Views: 150
Reputation: 179046
The reason with
is being used is to close over the value of b[a]
within the function, the correct replacement is with a closure:
(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);
Upvotes: 8