Possible Duplicate:
How do JavaScript closures work?
I've read all the million duplicates of the same old javascript closure loop issue. I thought I understood them, and have been using closures for months without issue, until today. I am stumped.
for (var i in groups){
for(var j in groups[i]){
$(unique_form).die('submit').live('submit'), function{
function (groups2, i2, j2){
return function(){alert(groups2[i2][j2])}
}(groups, i, j)
}
});
}
}
}
When I submit each unique form - I keep getting an alert for the last element of groups[i][j]. Obviously, I'm doing something stupid, what is it? I thought that by creating the anonymous function groups2, i2, and j2 I was solving the problem.