JavaScript中的激活和变量对象

JavaScript中的激活和变量对象

本文介绍了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:

然后使用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:

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

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

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

09-05 13:25