Possible Duplicate:
How do JavaScript closures work?
I understand that one issues people have with closures is that it returns the lastest value for a given variable unless you do this:
function f() {
var a = [];
var i;
for (i = 0; i < 3; i++) {
a[i] = (function (x) {
return function () {
return x;
}
})(i);
}
return a;
}
}
There is a little too much going on there that I need explained.