Javascript equivalent of Python's locals()?
javascript, python
Solution
locals() - No.
globals() - Yes.
`window` is a reference to the global scope, like `globals()` in python.
globals()["foo"]
is the same as:
window["foo"]
Problem
In Python one can get a dictionary of all local and global variables in the current scope with the built-in functions `locals()` and `globals()`. Is there some equivalent way of doing this in Javascript? For instance, I would like to do something like the following: ``` var foo = function(){ alert('foo'); }; var bar = function(){ alert('bar'); }; var s = 'foo'; locals()[s](); // alerts 'foo' ``` Is this at all possible, or should I just be using a local object for the lookup?