Q: Javascript closure freezing values of incrementer 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.

A: The easiest option here is generally to define a function that returns your handler:
function getHandler(row, column)
    return function () {
        var position = CalculatePosition($(this));
        alert("row:" + row + ",column:" + column);
        // ...
    };
}

Then call this function in your loop to get your handler with the relevant variables "fixed" to their values at call time:
for (row = 0; row < 10; row++) {
    for (column = 0; column < 10; column++) {
        var target = $("#" + Data.Row[row].Column[column].ID);
        target.mouseenter(getHandler(row, column));
    }
}

You  can also do this within the loop, in an immediately executing anonymous function:
for (row = 0; row < 10; row++) {
    for (column = 0; column < 10; column++) {
        var target = $("#" + Data.Row[row].Column[column].ID);
        target.mouseenter((function(row, column) {
            return function () {
                var position = CalculatePosition($(this));

                alert("row:" + row + ",column:" + column);

                ...
            };
        })(row, column)));
    }
}

But IMO that's a lot uglier and harder to read.
In either case, the basic approach here is to establish a new function scope, using the loop variables as arguments; now when you use them in the handler callback, they're no longer references to outer-scope variables.

A: You can use bind like so (the first argument is the context (this arg)):
target.mouseenter(function(row, column){
    ...
}.bind(target[0], row, column));

But bind is not cross browser, and you are already using jQuery, so you should use proxy instead:
target.mouseenter($.proxy(function(row, column){
    ...
}, target[0], row, column));

