william malo
william malo

Reputation: 2506

how do I get rid of "with()" in this function?

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?

Original Code:

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

Formatted code for reference:

(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

Answers (1)

zzzzBov
zzzzBov

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

Related Questions