What is extended mode?

前端 未结 2 637
抹茶落季
抹茶落季 2020-12-30 20:25

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条回答
  • 2020-12-30 20:48

    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 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:

    • 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 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 ???.

    • 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 ???.

    • 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.

    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:

    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.

    0 讨论(0)
  • 2020-12-30 21:00

    How to obtain harmony in your node.js

    The --harmony flag enables ES Harmony features. it seems that --harmony enables new ECMA features in the language, based on the v8, proxies, weak maps, sets, maps, typeof semantics, and block scoping are available when this flag is being used and these are extended features and after extending these features you can use for example let (for block scoping) with strict mode enabled only because it's based on it, otherwise it will throw

    SyntaxError: Illegal let declaration outside extended mode.

    Extended Mode : When you are using new ECMA features (ECMAScript 5), you are in the extended mode of the language and in this mode ECMAScript’s new features (extended code) and syntax could be used only in strict mode

    Concept of “extended code” that means code that may use new Es.next syntax.

    Harmony :

    "Harmony" is the name of the major upgrade to JavaScript due to arrive by the end of 2013. In 2008, after much controversy, the ECMA Technical Committee 39, that had been charged with creating the next generation of JavaScript, agreed to work together on a "Harmony" update to JavaScript and it has been in development since then. A number of the proposed features of Harmony are supported by Google's implementation. These include block scoped bindings and the addition of the let keyword, efficient maps and sets to remove the need to "abuse objects as dictionaries", weak maps for garbage collectable key/value tables and proxies which can simulate any JavaScript object or function to enable customisation.

    Some good reads here and hear. Also from Chromium Blog.

    Also from Paul Irish :

    François Beaufort (originally shared): A new flag named Enable Experimental JavaScript appeared in the chrome://flags page of the last Chromium build. This flag enables web pages to use experimental JavaScript features.

    To use extended mode/harmony features now in Chrome we have to enable this and we can enable this by navigating to chrome://flags and can toggle (enable/disable) on "Experimental JavaScript features".

    0 讨论(0)
提交回复
热议问题