I'm having a tough time understanding and using closures (yes, I have read How do JavaScript closures work?)
My problem is as follows:
for (row = 0; row < 10; row++) {
for (column = 0; column < 10; column++) {
var target = $("#" + Data.Row[row].Column[column].ID);
target.mouseenter(function () {
var position = CalculatePosition($(this));
alert("row:" + row + ",column:" + column);
...
});
}
}
As you might expect, row and column is always 9 whenever target has the mouse over it. My question is then, how can I freeze the value of row and column so that the mouseevent anonymous function can get their intended values? I tried doing something like
target.mouseenter(function() {}.bind(column));
And that seems to work for just column, but then of course this
is no longer referring to target.