词汇环境和功能范围 [英] Lexical environment and function scope

查看:72
本文介绍了词汇环境和功能范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是规范说的关于词汇环境


Lexical Environment是一种规范类型,用于基于ECMAScript代码的词法嵌套结构定义标识符与特定变量和函数的关联。词法环境由一个环境记录和一个可能为空的外部词法环境引用组成。


基于此,我会说是,这就是人们通常在谈到范围时所谈论的内容。



尽管可能会认为范围实际上定义为声明性环境记录


每个声明式环境记录都与包含变量和/或函数声明的ECMAScript程序范围相关联。声明式环境记录绑定由其作用域中包含的声明定义的标识符集合。


如果您将范围一个包含标识符和值之间绑定的东西,那么第二个定义可能更适合。如果你认为它是知道其祖先范围的东西,那么第一个定义更适合。

编辑:和第三个选项是执行环境


Is lexical environment and scope in javascript one and the same thing?

解决方案

Here's what the spec says about lexical environments:

A Lexical Environment is a specification type used to define the association of Identifiers to specific variables and functions based upon the lexical nesting structure of ECMAScript code. A Lexical Environment consists of an Environment Record and a possibly null reference to an outer Lexical Environment.

Based on that, I would say yes, that's what people are usually talking about when they say "scope".

Although it could probably be argued that a "scope" is actually defined as a "Declarative Environment Record":

Each declarative environment record is associated with an ECMAScript program scope containing variable and/or function declarations. A declarative environment record binds the set of identifiers defined by the declarations contained within its scope.

If you think of a "scope" as a thing that contains bindings between identifiers and values, then the 2nd definition probably fits better. If you think of it as something that is aware of its ancestor scopes, then the first definition fits better.

Edit: and a third option is "Execution Context".

这篇关于词汇环境和功能范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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