Closing over the loop variable, part two

(This is part two of a two-part series on the loop-variable-closure problem. Part one is here.) UPDATE: We are taking the breaking change. In C# 5, the loop variable of a foreach will be logically inside the loop, and therefore closures will close over a fresh copy of the variable each time. The “for” loop…

51

Closing over the loop variable considered harmful

(This is part one of a two-part series on the loop-variable-closure problem. Part two is here.) UPDATE: We are taking the breaking change. In C# 5, the loop variable of a foreach will be logically inside the loop, and therefore closures will close over a fresh copy of the variable each time. The “for” loop…

134

What are closures?

JScript, as I noted yesterday, is a functional language. That doesn’t mean that it works particularly well (though I hope it does) but rather that it treats functions as first-class objects. Functions can be passed around and assigned to variables just as strings or integers can be. A reader commented yesterday that “closures are your…

23