简体   繁体   中英

Access all local variables

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?

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.

你会在每个函数中得到一个名为“arguments”的隐式数组,但除此之外没有这样的东西。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM