Alright. Thanks for the answer attempts, but after much annoyance and research, I don't think it is possible to do exactly what I was trying to do, but I got close enough for my project.
Dead ends: I was able to access the contents of variables up the scope chain using V8's stack trace and faking an error. I couldn't manage to write to the scope up the chain though. Plus that is somewhat insane. I also went down the route of trying to do some Object.defineProperty
trickery, but I never could get that to work exactly as needed.
For my purpose, it works to put everything into an object then use with
which is slightly less evil than globals. For the situation I need, it works fine. So, like this:
var local = {
a : '1',
b : '2',
c : '3'
};
function contained() {
with (local) {
console.log(a,b,c);
}
}
console.log(typeof a) //undefined
contained();
Now I'll just pass the local object through the module and have the script or other module use with
where needed. Not quite as syntactically pure as I would have liked. I also think that implicit variables should be local only to the module since you can access globals using the global.foo
(I know, not going to happen, would break the internet and so on)