JavaScript中的激活和变量对象? [英] Activation and Variable Object in JavaScript?

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

问题描述

术语激活对象只是变量对象的另一个名称,还是它们之间实际上有什么区别?我一直在阅读一些关于如何在执行上下文中形成变量作用域的JavaScript文章,从我的观点来看,似乎在大多数文章中他们可以互换地使用这两个术语。

Is the term "activation object" just another name of "variable object" or is there actually any difference between them? I have been reading a few JavaScript articles about how variable scopes are formed in an execution context, and from my point of view it seems that in most of the articles they use these two terms interchangeably.

推荐答案

好吧,我刚学到了东西:)。从本文开始,在函数的执行上下文中显示,激活Object用作变量对象:

Well, I just learned something :). From this article, it would appear that within the execution context of a function, the Activation Object is used as the Variable Object:


当创建执行上下文时,会按定义的顺序发生许多事情。首先,在函数的执行上下文中,创建激活对象。 [...]

When an execution context is created a number of things happen in a defined order. First, in the execution context of a function, an "Activation" object is created. [...]

然后使用ECMA 262称为变量对象的对象进行变量实例化过程。但是,Activation对象用作Variable对象(请注意,重要的是:它们是同一个对象)。为每个函数的形式参数创建Variable对象的命名属性,如果函数调用的参数与这些参数对应,则将这些参数的值分配给属性(否则指定的值未定义)。

Then the process of "variable instantiation" takes place using an object that ECMA 262 refers to as the "Variable" object. However, the Activation object is used as the Variable object (note this, it is important: they are the same object). Named properties of the Variable object are created for each of the function's formal parameters, and if arguments to the function call correspond with those parameters the values of those arguments are assigned to the properties (otherwise the assigned value is undefined).

但是,当您在全局范围内时,没有激活对象,因此全局对象将用作变量对象:

However, when you're in the global scope, there isn't an Activation Object, so the Global Object is used as the Variable Object instead:


全局执行上下文处理略有不同,因为它没有参数,所以它不需要定义的Activation对象来引用它们。 [...]全局对象用作Variable对象,这就是全局声明的函数成为全局对象的属性的原因。

The global execution context gets some slightly different handling as it does not have arguments so it does not need a defined Activation object to refer to them. [...] The global object is used as the Variable object, which is why globally declared functions become properties of the global object.

所以听起来激活对象和变量对象在函数上下文中是相同的,但不在全局上下文中。

So it sounds like "Activation Object" and "Variable Object" are the same thing within a function context, but not within the global context.

这篇关于JavaScript中的激活和变量对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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