function coolo()
{
var tile1 = -1;
var tile2 = -1;
$(".grid-cell").click(swap);
}
function swap()
{
console.log(tile1)
}
coolo();
Of course I will get a Uncaught ReferenceError: tile1 is not defined error. I can fix it by passing the variable to the function or putting the variable in global scope. Is there a way for the swap function to access variables in the scope of coolo? I can access variables in global scope, so why not this? I've tried using the this keyword, but jquery assigns this to the dom element that has been selected. I'm not sure if using this would work in a non jquery situation either. If there isn't, I'd like to learn more about how scoping works in javascript.
function swap(tile1)....click(swap.bind(null, tile1))