This is the essence of a bigger problem I have:
I get sequence (0, 2), (1, 2), (2, 2) using this code:
var f = [];
var i, a;
for (i = 0; i < 3; i++) {
a = i;
f.push(function() { alert(i+", "+a); });
}
for (var i = 0; i < 3; i++) f[i]();
Why are both values different in each alert?