[js]var callback = function callback() { alert(x);}; function foo() { var x = 7; callback(); //Wanting callback to have access to x}; foo();[/js]
It's for a parser where variables will be available to a function depending upon the state of the parser. I sort of expected the above to work, but I guess the function remains in the scope in which it was defined. Knowing how funk JS is, does anyone know if there's some sort of hack to get the above to work? I thought about something with "new Function(stringVersionOfOtherFunction)" but couldn't get that to work.
EDIT | I do have a back-up plan of just passing in arguments, but I'm curious more than anything