简体   繁体   English

访问所有本地变量

[英]Access all local variables

Every global variable in javascript is a property of 'window' javascript中的每个全局变量都是'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. 显然所有局部变量(以及参数)都存储为“调用对象”的属性(参见每个函数的第4.6.2章。可能只在所述函数的生命周期内存在。)

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." “激活对象纯粹是一种规范机制.ECMAScript程序不可能访问激活对象。”

Turns out ECMAScript states I am not allowed to access it. 结果证明ECMAScript状态我不允许访问它。

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. 不可以。在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. 从理论上讲,实现可以提供一个扩展,允许代码检查当前的Variable对象(也就是函数中的Activation对象;“Call object”是由Flanagan组成的术语,在ECMAScript规范中没有提到)但是没有实现,我知道这样做。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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