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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
好吧,我刚刚学到了一些东西:)。从这篇文章来看,在函数的执行上下文中,激活对象用作变量对象:
但是,当您处于全局范围内时,没有激活对象,因此全局对象将用作变量对象:
因此,听起来“激活对象”和“变量对象”在函数上下文中是同一件事,但在全局上下文中却不是。
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:
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.
激活对象是作用域链中最上面的对象,最下面的是全局对象。
而变量对象是抽象概念,因此根据其执行上下文,可以是作用域链中的任何链接,包括激活/全局对象。
它包含:
arguments
的对象(如果您希望函数支持多个签名)。它不包含:
this
(因为它不是变量);更多信息 - JavaScript。核心。
在 tl;dr 的情况下很少引用:
An activation object is the uppermost object in a scope-chain with the lowermost being global object.
Whereas variable object is abstract concept and therefore, depending on its execution context, is any link in scope-chain including activation/global object.
It contains:
arguments
(in case you want your function to support multiple signatures).It doesn't contain:
this
(as it's not a variable);Further info - JavaScript. The core.
Few quotes in case of tl;dr:
更准确地说,Activation 对象是 Variable 对象的一种类型。这类似于男人是人类的一种。正如此处所述,术语“变量对象”只是一个广义的用于描述任何对象的术语,该对象拥有描述当前执行上下文的环境和范围的属性。
因此,在全局执行上下文中(即在任何函数之外),它最终成为全局对象。为什么?因为它是保存描述全局执行上下文的环境和范围的属性的对象。
而在函数本地执行上下文中(即在函数内),函数本地对象(也称为激活对象)是变量对象,因为它是保存描述当前环境和范围的属性的对象。执行函数。例如函数参数等属性。
It's more accurate to say that an Activation object is a type of Variable object. This is similar to how a man is a type of HUMAN. As stated here, the term 'Variable object' is just a GENERALISED term used to describe any object that holds the properties that describe the environment and scope of the currently executing context.
Hence, within the global executing context (i.e., outside of any functions), it ends up being the Global object. Why? Because it’s the object that holds the properties that describe the environment and scope of the global executing context.
Whereas within the function local executing context (i.e., within a function), it is the function local object (a.k.a the Activation object) that is the Variable object, as it's the object that holds the properties that describe the environment and scope of the currently executing function. Properties such as function arguments for example.
激活的对象仅意味着代表发生事件的网页上的元素的对象。因此,如果单击图像,表示该图像的 JavaScript 对象就是激活的对象。
An activated object just means an object that represents an element on a web page that an event occurred on. So if an image is clicked, the JavaScript object that represents that image is the activated object.