在运行时在模块中启用V8中的Harmony ES6功能?

Eva*_*oll 7 v8 node.js ecmascript-harmony

Node v0.10.20提供了许多与和声有关的选项,

--harmony_typeof (enable harmony semantics for typeof)
--harmony_scoping (enable harmony block scoping)
--harmony_modules (enable harmony modules (implies block scoping)
--harmony_proxies (enable harmony proxies)
--harmony_collections (enable harmony collections (sets, maps, and weak maps))
--harmony (enable all harmony features (except typeof))
Run Code Online (Sandbox Code Playgroud)

我知道这些不是生产就绪的功能,而且它们正在开发中,但其中很多都足够好.

有没有办法在运行时启用它们?

"use strict";
"use harmony collections";
Run Code Online (Sandbox Code Playgroud)

像上面这样的东西.即使它不仅仅是模块级别启用这些功能,最好确保它们在模块内部启用而不是假设它们已启用.

And*_*erg 10

不,你不能.事实上,如果你试图在同一个V8实例中偷偷进入这些标志的多个不同设置,那么在V8内部可能会出现一些可能错误的事情(披露:我实现了大部分这些标志).


mic*_*nic 1

没有办法做到这一点,解释器读取模块的内容,然后验证它们,然后评估它们。如果您将使用某些 ES6 特定语法,那么验证将失败并且代码将不会被评估。

您只能隔离 ES6 语法文件并将它们作为子进程运行(带有必要的选项),但我想这不是您想要的方式。