javascript - JavaScript 中的激活和变量对象?

标签 javascript ecma262

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

最佳答案

好吧,我刚刚学到了一些东西:)。来自 this article ,看起来在函数的执行上下文中,激活对象被用作变量对象:

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. [...]

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


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

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.


所以听起来“激活对象”和“变量对象”在函数上下文中是同一回事,但在全局上下文中不同。

关于javascript - JavaScript 中的激活和变量对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6337344/

相关文章:

javascript - Nodejs : Can not read property of null

javascript - 表单重置后禁用“保存/提交”按钮

JavaScript中的事件委托(delegate)

javascript - Ecma-262 (EcmaScript 5) 将如何帮助您?

JavaScript 闭包 - 使用 ECMA 规范,请解释闭包是如何创建和维护的

javascript - 为什么我的自动完成功能不起作用?

javascript - 如何从外部服务器获取 JSON

javascript - 哪些(javascript)环境支持 ECMAscript 5 严格模式? (又名 "use strict")

javascript - ecma262 中的赋值表达式