本文介绍了为什么变量对象在ES5中被改为词汇环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ES5将(VO)更改为词汇环境。这种变化的动机是什么,因为VO作为感知已经非常明显了?

ES5 changed variable object(VO) to lexical environment. What's the motivation of such change since VO is already very obvious as perception?

推荐答案

我认为变量对象更像是。

I think variable objects are more analogous to environment records.

在ES5中有两种不同的环境记录:

In ES5 there are two different kinds of environment records:

所以问题是为什么引入声明性环境记录而不是仅使用对象环境记录,就像ES3变量对象一样。区别在于可以有不可变绑定:

So the question would be why declarative environment records were introduced instead of only using object environment records just like ES3 variable objects. The difference is that declarative environment records can have immutable bindings:

不可变绑定在对象中没有直接的等价物。属性可以定义为不可配置和不可写,变为不可变。但是,

Immutable bindings don't have a direct equivalent in objects. A property can be defined as both non-configurable and non-writable, becoming immutable. However,

但您不能拥有未初始化的财产。如果您定义一个值不可定义的不可配置的不可写属性,那么您将无法将其初始化为所需的值。

But you can't have an uninitialized property. If you define a non-configurable non-writable property with value undefined, then you won't be able to initialize it to the desired value.

我不认为在ES5中可以使用未初始化的不可变绑定。 CreateImmutableBinding仅用于和,在这两种情况下,它都会立即用InitializeImmutableBinding初始化。

I don't think it's possible to have uninitialized immutable bindings in ES5. CreateImmutableBinding is only used in Declaration Binding Instantiation and Function Definition, and in both cases it's immediately initialized with InitializeImmutableBinding.

但可能这样做是为了允许未初始化的不可变绑定作为语言的扩展,如JavaScript 1.5 const 。或许他们已经考虑过ES6 const

But possibly this was done to allow uninitialized immutable bindings as extensions of the language, like the JavaScript 1.5 const. Or maybe they already had in mind ES6 const.

这篇关于为什么变量对象在ES5中被改为词汇环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 10:58