Every global variable in javascript is a property of 'window'
Apparently all local variable (aswell as arguments) are stored as properties of the 'Call object' (See chapter 4.6.2 of each function. Persumably only existing for the lifetime of said function.
Basically I want to be able to do
for (var obj in CallObject ) { // }
Can I access said object containing local variables and if so how? Alternatively is there any other way of accessing all local variables of a function.
[Edit]
It turns out that arguments is a property of the Activation Object of a function. This has to be stored somewhere.
"The activation object is purely a specification mechanism. It is impossible for an ECMAScript program to access the activation object."
Turns out ECMAScript states I am not allowed to access it.
What about accessing arguments properties and somehow chaining up to local variables?
We can access global variable if there is a local variable with same name in C and C++ through Extern and Scope resolution operator respectively.
Local variables can be accessed with the help of statements, inside a function in which they are declared. You can access global variables by any statement in the program. It is stored on the stack unless specified.
You can see scopes and their variables in [[Scopes]] , even closure scopes using console. dir() . It shows you the variables in "[[Scopes]] > Closure", "[[Scopes]] > Global" and even "[[Scopes]] > Script" if the page have scripts reachable. Even with nested closures you can see the nested scopes.
No. There is no way of doing this in any browser implementation of JavaScript.
It's theoretically possible that an implementation could provide an extension to allow code to inspect the current Variable object (aka the Activation object within a function; "Call object" is a term made up by Flanagan that is not mentioned anywhere within the ECMAScript spec) but no implementation I know of does this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With