I'm creating a sort of dsl that lies inside of javascript - and for it to be as clean as possible, it is important that I don't have to specifically pass things to it, it can just pick them up anything in the current scope by name - but I'm wondering if it is actually possible. If I'm in a function, is there any way to access local variables from the caller function?
I know you aren't supposed to be able to do this, but it's all out there on the stack, a debugger can do it, and there doesn't seem to be a lot of restrictions on what you can to in javascript, so I'm wondering if there's some obscure way, even if it's intensely hacky.
eg
function dsl( someString )
{
// can I access bob and cindy here?
}
function someRealFunction()
{
var bob = [1,2,3,4];
var cindy = [1,2,3,8];
return dsl("difference bob and cindy");
}
This is slightly different from the question about passing scope to another function, because I don't want to pass scope - I just want to implicitly pick up the scope which is there. A debugger can do it, so fundamentally the information IS actually there - the question is whether it can be accessed.