访问所有本地变量 [英] Access all local variables

查看:119
本文介绍了访问所有本地变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

javascript中的每个全局变量都是'window'的属性

Every global variable in javascript is a property of 'window'

显然所有局部变量(以及参数)都存储为'Call object'(参见每个函数的第4.6.2章。仅适用于在所述函数的生命周期中存在。

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.

基本上我希望能够做到

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.

事实证明,参数是激活对象的属性一个功能。这必须存储在某个地方。

It turns out that arguments is a property of the Activation Object of a function. This has to be stored somewhere.


激活对象纯粹是
规范机制。对于ECMAScript程序,
不可能是

访问激活对象。

"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.

如何访问参数属性并以某种方式链接到局部变量?

What about accessing arguments properties and somehow chaining up to local variables?

推荐答案

没有。在任何JavaScript的浏览器实现中都无法做到这一点。

No. There is no way of doing this in any browser implementation of JavaScript.

从理论上讲,实现可以提供扩展以允许代码检查当前的Variable对象(aka函数中的Activation对象;调用对象是由Flanagan组成的术语,在ECMAScript规范中没有提到过,但我知道没有实现这一点。

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.

这篇关于访问所有本地变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆