关于“LexicalEnvironment”之间差异的清晰度。和“VariableEnvironment”和“VariableEnvironment”。在ECMAScript / JavaScript中 [英] Clarity on the difference between "LexicalEnvironment" and "VariableEnvironment" in ECMAScript/JavaScript

查看:217
本文介绍了关于“LexicalEnvironment”之间差异的清晰度。和“VariableEnvironment”和“VariableEnvironment”。在ECMAScript / JavaScript中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以澄清这两者之间的区别,因为它们存在于执行上下文中吗?我很难阅读 ECMA 262 v 5 规范并清楚地看到差异。

Could someone clarify what the difference is between these two, as they exist in the Execution context? It's hard for me to read the ECMA 262 v 5 specification and clearly see the difference.

谢谢,

推荐答案

两者是执行上下文的组件(相同类型),但它们用于不同的目的(来自规范):

Both are components (of the same type) of Execution Contexts, but they serve distinct purposes (from the spec):

LexicalEnvironment


标识用于解析此执行上下文中的代码所做的标识符引用的词汇环境

VariableEnvironment


标识词汇环境其环境记录包含由此执行上下文中的VariableStatements和FunctionDeclarations创建的绑定。

Identifies the Lexical Environment whose environment record holds bindings created by VariableStatements and FunctionDeclarations within this execution context.

下一段解释了为什么它们需要不同:

The next paragraph explains why they need to be different:


当创建执行上下文时,它的LexicalEnvironment和VariableEnvironment组件最初具有相同的值。在执行上下文中执行代码期间,当LexicalEnvironment组件的值可能会发生变化时,VariableEnvironment组件的值永远不会更改

When an execution context is created its LexicalEnvironment and VariableEnvironment components initially have the same value. The value of the VariableEnvironment component never changes while the value of the LexicalEnvironment component may change during execution of code within an execution context.

这种情况并不经常发生,通常都引用相同的词汇环境。在为什么catch条款有自己的词汇环境?的问题中给出了改变LexicalEnvironment的一个很好的例子。 - 参见§12.14。我在规范中找到的另一个地方是带语句§12.10)其中 对象环境记录 动态用于标识符解析 - 但变量/函数声明是静态的。

That does not happen often and usually both refer to the same Lexical Environment. A good example for a changing LexicalEnvironment is given in the question Why do catch clauses have their own lexical environment? - see §12.14. The other place I could find in the spec where this happens are With Statements (§12.10) where an Object Environment Record is dynamically used for the identifier resolution - yet variable/function declarations are static.

这篇关于关于“LexicalEnvironment”之间差异的清晰度。和“VariableEnvironment”和“VariableEnvironment”。在ECMAScript / JavaScript中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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