什么是扩展模式? [英] What is extended mode?

查看:1034
本文介绍了什么是扩展模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Node v0.10.12中的 let 使用 - 和声标记以下代码会产生语法错误:

I'm toying with let in Node v0.10.12. Using the --harmony flag the following code produces a syntax error:

for (let i = 0; i < 2; i += 1) {
    console.log('i', i);
}




语法错误:扩展模式之外的非法let声明

SyntaxError: Illegal let declaration outside extended mode

但是,如果我还使用 - use-strict 标志,那么代码按预期运行。

However, if I also use the --use-strict flag, then the code runs as expected.

为什么只使用 - 和声标志时会抛出语法错误?什么是扩展模式?与严格模式的连接是什么?

Why is a syntax error thrown when just using the --harmony flag? What is extended mode? What is the connection with strict mode?

推荐答案

看起来像扩展模式从当前开发版本的和谐规范在2012年2月27日,但有一个描述应该是在一个几个较旧的(这是2012年1月16日):

It looks like "extended mode" was removed from the current development version of the harmony spec on February 27, 2012, but there's a description of what it was supposed to be in a few older ones (this one is from January 16, 2012):


10.1.2扩展代码



扩展代码是包含在ECMAScript程序句法
单元中的任何代码,其中包含在ECMAScript
规范的第五版之后定义的词汇或语法生成
的出现。代码被解释为以下
情况下的扩展代码:

10.1.2 Extended Code

Extended code is any code contained in an ECMAScript Program syntactic unit that contains occurrences of lexical or syntactic productions defined subsequent to the Fifth Edition of the ECMAScript specification. Code is interpreted as extended code in the following situations:


  • 如果包含全局代码,扩展全局代码在一个ECMAScript程序句法单元中,已经以实现定义的方式被指定为
    扩展程序单元,或者如果?。

  • Global code is extended global code if it is contained in an ECMAScript Program syntactic unit that has been designated as an extended Program unit in an implementation defined manner or if ???.

评估代码如果对eval的调用是直接调用(参见15.1.2.1.1)到包含在
扩展模式代码中的eval函数,或者如果以...开头,则扩展eval代码。

Eval code is extended eval code if the call to eval is a direct call (see 15.1.2.1.1) to the eval function that is contained in extended mode code or if it begins with ???.

功能代码是功能代码, FunctionExpression 或访问器 PropertyAssignment 是扩展功能代码,如果它的 FunctionDeclaration FunctionExpression
PropertyAssignment 包含在扩展模式代码中,或者如果函数代码以。开头。

Function code that is part of a FunctionDeclaration, FunctionExpression, or accessor PropertyAssignment is extended function code if its FunctionDeclaration, FunctionExpression, or PropertyAssignment is contained in extended mode code or if the function code begins with ???.

作为内置函数构造函数的最后一个参数提供的函数代码是严格的函数代码,如果最后一个参数是a
作为 FunctionBody 处理的字符串以。开头。

Function code that is supplied as the last argument to the built-in Function constructor is strict function code if the last argument is a String that when processed as a FunctionBody begins with ???.

术语严格代码用于指定实际严格模式
代码和扩展代码,而术语扩展代码仅指定
实际扩展代码。术语基本代码用于指定不是扩展代码的代码

The term "strict code" is used to designate both actual strict mode code and extended code while the term "extended code" only designates actual extended code. The term "base code" is used to designate code that is not extended code.

关于严格的连接模式,这似乎是V8(实验)实现的具体。以下是修订版本10062的更改日志,其中介绍了 -harmony 标志,说:

As for the connection with strict mode, that seems to be specific to V8's (experimental) implementation. Here's what the changelog for revision 10062, which introduced the --harmony flag, says:


这个CL引入了第三种模式旁边的非严格(今后
称为经典模式)和严格模式,称为扩展
模式,与当前ES.next规范草案一样。扩展的
模式基于严格模式,并为其添加新功能。
这意味着这两种模式的大部分语义是一致的。

This CL introduces a third mode next to the non-strict (henceforth called 'classic mode') and 'strict mode' which is called 'extended mode' as in the current ES.next specification drafts. The extended mode is based on the 'strict mode' and adds new functionality to it. This means that most of the semantics of these two modes coincide.

输入扩展模式而不是严格模式
解析时使用严格模式指令使用严格,当
和谐范围标志是活动的。
一旦它
完全指定如何输入扩展模式。

The 'extended mode' is entered instead of the 'strict mode' during parsing when using the 'strict mode' directive "use strict" and when the the harmony-scoping flag is active. This should be changed once it is fully specified how the 'extended mode' is entered.

这篇关于什么是扩展模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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