javascript - Access all local variables - Stack Overflow

Every global variable in javascript is a property of 'window'Apparently all local variable (a

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?

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?

Share Improve this question edited Sep 30, 2010 at 15:49 Raynos asked Sep 30, 2010 at 15:08 RaynosRaynos 170k57 gold badges357 silver badges398 bronze badges 1
  • 2 There's not a way to do that in Javascript. Also, globals aren't (strictly speaking) always properties of "window" - it depends on where the interpreter is running. In a server-side Javascript program running in V8 or Rhino, for example, there's no "window" but there is a "global context" object that plays the same role (as far as your question goes). – Pointy Commented Sep 30, 2010 at 15:14
Add a ment  | 

2 Answers 2

Reset to default 4

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.

You get an implicit array called "arguments" in every function but beside this there is no such thing.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744293718a4567156.html

相关推荐

  • javascript - Access all local variables - Stack Overflow

    Every global variable in javascript is a property of 'window'Apparently all local variable (a

    7天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信