gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 11:36:04 25 4
gpt4 key购买 nike

术语“激活对象”只是“变量对象”的另一个名称,还是它们之间实际上有任何区别?我一直在阅读一些关于如何在执行上下文中形成变量范围的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com