执行上下文和词汇环境之间有什么区别和关系? [英] What is the difference and relationship between execution context and lexical environment?

查看:108
本文介绍了执行上下文和词汇环境之间有什么区别和关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JavaScript中:理解奇怪的部分词汇环境被解释为代码的范围,而执行上下文是词汇环境的集合,并且它包含超出编写代码的内容。

In JavaScript: Understanding the Weird Parts lexical environment is explained as the scope of your code while execution context is a collection of lexical environments, and that it includes stuff beyond your written code.

这些术语的描述在功能上仍然存在重叠,并且不清楚执行上下文的作用或执行方式。

The descriptions of these terms still sound overlapping in functionality and it's unclear as to what execution context does or how it does it.

推荐答案

考虑执行上下文的最佳方式是作为堆栈框架,而词汇环境确实是范围

The best way to think of an execution context is as a stack frame, while lexical environments are indeed the scopes.

各自的规格章节(§8.1词汇环境§8.3执行上下文)解释:

The respective spec chapters (§8.1 Lexical Environments and §8.3 Execution Contexts) explain:


  • 执行上下文包含当前评估的代码状态,参考代码(函数)本身,以及可能对当前词法环境的引用。

    执行上下文在堆栈中管理。

  • 词法环境包含环境记录变量存储的位置,以及对其父环境的引用(如果有的话)。

    词法环境构建树结构。

随着执行上下文的每次更改,词法环境也会发生变化。然而,词汇环境也可能独立地改变,例如在进入区块时。

With every change of the execution context, the lexical environment changes as well. However the lexical environment may change independently from that as well, for example when entering a block.

这篇关于执行上下文和词汇环境之间有什么区别和关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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