lexical for-in/for-of loose end
Jason Orendorff
jason.orendorff at gmail.com
Sat Feb 4 06:39:17 PST 2012
On Fri, Feb 3, 2012 at 6:13 PM, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:
> On Feb 3, 2012, at 12:44 PM, Jason Orendorff wrote:
> It might also be useful to look at for(var ...;...;...) and for (...;...;...) loops. Nobody is proposing changing the scoping for those, but they might provide a broader view of how people use the generality of for(;;) loops
Out of about 5,500 for loops, I found none with functions in the head.
Actually, though, Mozilla's codebase is no better than anyone else's
for that purpose. I only picked ours because we have 'let'. I wish we
had a bigger corpus to search.
This is excluding tests generated by Mozilla's JS fuzzers; the fuzzers
often says things like:
for(e in this.__defineSetter__("x",function(){})){}
...and much worse.
> I would actually feel a lot more comfortable with per iteration binding of for(;;) if the for let declaration was limited to a single binding.
Of course, that would inconvenience people doing simple stuff that has
nothing to do with closures, as in:
for (let i = 0, n = a.length; i < n; i++)
for (let child = element.firstChild, stop = element.lastChild;
child !== stop; child = child.nextSibling)
My sense is that these uses are even more common than for-loops with
escaping closures.
-j
More information about the es-discuss
mailing list