ECMAScript 2015 (ES6) 及更高版本
¥ECMAScript 2015 (ES6) and beyond
Node.js 是针对 V8 的现代版本构建的。通过随时了解此引擎的最新版本,我们确保及时将 JavaScript ECMA-262 规范 的新功能带给 Node.js 开发者,并持续提高性能和稳定性。
¥Node.js is built against modern versions of V8. By keeping up-to-date with the latest releases of this engine, we ensure new features from the JavaScript ECMA-262 specification are brought to Node.js developers in a timely manner, as well as continued performance and stability improvements.
所有 ECMAScript 2015 (ES6) 功能分为三组,即交付中、暂存和进行中功能:
¥All ECMAScript 2015 (ES6) features are split into three groups for shipping, staged, and in progress features:
-
V8 认为稳定的所有交付中的功能在 Node.js 上默认启用,并且不需要任何类型的运行时标志。
¥All shipping features, which V8 considers stable, are turned on by default on Node.js and do NOT require any kind of runtime flag.
-
暂存功能是 V8 团队认为不稳定的几乎完成的功能,需要运行时标志:
--harmony
。¥Staged features, which are almost-completed features that are not considered stable by the V8 team, require a runtime flag:
--harmony
. -
正在进行的功能可以通过各自的和谐标志单独激活,但除非出于测试目的,否则强烈不建议这样做。注意:这些标志由 V8 公开,可能会在没有任何弃用通知的情况下发生变化。
¥In progress features can be activated individually by their respective harmony flag, although this is highly discouraged unless for testing purposes. Note: these flags are exposed by V8 and will potentially change without any deprecation notice.
默认情况下,哪些功能随哪个 Node.js 版本一起提供?
¥Which features ship with which Node.js version by default?
网站 node.green 基于 kangax 的兼容表,提供了对 Node.js 各个版本支持的 ECMAScript 功能的出色概述。
¥The website node.green provides an excellent overview over supported ECMAScript features in various versions of Node.js, based on kangax's compat-table.
哪些功能正在进行中?
¥Which features are in progress?
V8 引擎不断添加新功能。一般来说,预计它们会在未来的 Node.js 版本中实现,尽管具体时间未知。
¥New features are constantly being added to the V8 engine. Generally speaking, expect them to land on a future Node.js release, although timing is unknown.
你可以通过 --v8-options
参数 grepping 列出每个 Node.js 版本上可用的所有正在进行的功能。请注意,这些是 V8 的不完整且可能损坏的功能,因此使用它们需要你自担风险:
¥You may list all the in progress features available on each Node.js release by grepping through the --v8-options
argument. Please note that these are incomplete and possibly broken features of V8, so use them at your own risk:
node --v8-options | grep "in progress"
我已经设置了基础架构以利用 --harmony 标志。我应该删除它吗?
¥I have my infrastructure set up to leverage the --harmony flag. Should I remove it?
Node.js 上 --harmony
标志的当前行为是仅启用分阶段功能。毕竟,它现在是 --es_staging
的同义词。如上所述,这些是尚未被视为稳定的已完成功能。如果你想安全行事,尤其是在生产环境中,请考虑删除此运行时标志,直到它在 V8 上默认发布,从而在 Node.js 上发布。如果你保持启用此功能,如果 V8 更改其语义以更紧密地遵循标准,你应该为进一步的 Node.js 升级做好准备,以破坏你的代码。
¥The current behavior of the --harmony
flag on Node.js is to enable staged features only. After all, it is now a synonym of --es_staging
. As mentioned above, these are completed features that have not been considered stable yet. If you want to play safe, especially on production environments, consider removing this runtime flag until it ships by default on V8 and, consequently, on Node.js. If you keep this enabled, you should be prepared for further Node.js upgrades to break your code if V8 changes their semantics to more closely follow the standard.
如何找到特定版本的 Node.js 附带的 V8 版本?
¥How do I find which version of V8 ships with a particular version of Node.js?
Node.js 提供了一种简单的方法来通过 process
全局对象列出特定二进制文件附带的所有依赖和相应版本。如果是 V8 引擎,请在终端中输入以下内容以检索其版本:
¥Node.js provides a simple way to list all dependencies and respective versions that ship with a specific binary through the process
global object. In case of the V8 engine, type the following in your terminal to retrieve its version:
node -p process.versions.v8