Javascript Node.js 0.12 中提供的 ECMAScript 6 功能
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28388885/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ECMAScript 6 features available in Node.js 0.12
提问by Robert Rossmann
A new stable release of Node.js (0.12) has landed recently with an upgraded Google's v8 JavaScript engine, v3.28.73.
Node.js (0.12) 的新稳定版本最近发布,其中包含升级后的谷歌 v8 JavaScript 引擎v3.28.73。
What ECMAScript 6 features are currently present in Node.js, without using the --harmonyflag?
Node.js 中当前存在哪些 ECMAScript 6 特性,但不使用该--harmony标志?
I have checked several sites claiming to list the ES 6 features but all of them seem out of date - most prominently, this table(Update:now updated with current Node.js status as of 0.12), because several of the features are listed as requiring the --harmonyflag while I found some of them being enabled by default (Maps, Sets, Symbols, to name a few). Update: Node specific tableshave since been made available
我检查了几个声称列出 ES 6 特性的站点,但它们似乎都过时了 - 最突出的是这张表(更新:现在更新为 0.12 的当前 Node.js 状态),因为其中一些特性被列为需要--harmony标志,而我发现其中一些默认启用(地图、集合、符号,仅举几例)。更新:节点特定的表已经可用
Also, trying to google this information purely for the v8 engine gives too up-to-date information - current v8 release is 4.2.*, which is quite ahead of what Node.js uses.
此外,试图纯粹为 v8 引擎搜索此信息会提供太最新的信息 - 当前 v8 版本是4.2.*,这远远领先于 Node.js 使用的版本。
My hopes are that this question (and its answers) will become a comprehensive summary on what ES 6 features are now available to Node.js developers.
我希望这个问题(及其答案)将成为 Node.js 开发人员现在可以使用的 ES 6 特性的综合总结。
ES 6 features enabled in Node.js 0.12 I currently know of:
我目前知道的在 Node.js 0.12 中启用的 ES 6 功能:
- Maps, Sets / WeakMaps, WeakSets
- Symbols
- Object.observe
- Promises
- Number
- .isInteger
- .isSafeInteger
- .isNaN
- .EPSILON
- .MIN_SAFE_INTEGER
- .MAX_SAFE_INTEGER
- Math
- .clz32
- .imul
- .sign
- .log10
- .log2
- .log1p
- .expm1
- .cosh
- .sinh
- .tanh
- .acosh
- .asinh
- .atanh
- .trunc
- .fround
- .cbrt
- .hypot
- Maps, Sets / WeakMaps, WeakSets
- 符号
- 对象观察
- 承诺
- 数字
- .isInteger
- .isSafeInteger
- .isNaN
- .EPSILON
- .MIN_SAFE_INTEGER
- .MAX_SAFE_INTEGER
- 数学
- .clz32
- .imul
- 。标志
- .log10
- .log2
- .log1p
- .expm1
- .cosh
- .sinh
- .tanh
- .acosh
- .asinh
- .atanh
- .trunc
- .fround
- .cbrt
- .hypot
回答by alexpods
Features without --harmonyflag:
无--harmony标志特点:
- "for-of" loop
- Map, Set, WeakMap, WeakSet(already specified in question)
- Symbol(already specified in question)
- Promise(already specified in question)
- Array methods:
- Object:
- .observe()(initially was planned for ES7, but was removed from the spec entirelyon November 2, 2015)
- .is()
- .setPrototypeOf()
- .getOwnPropertySymbols()
- .getNotifier() (not es6, example here)
- .apply() and .call() (not es6, same purpose as Funciton.prototype.call and Function.prototype.apply)
- Number properties and methods (already specified in question)
- Math methods (a lot of them) (already specified in question)
- constants
- “for-of”循环
- Map、Set、WeakMap、WeakSet(已在问题中指定)
- 符号(已在问题中指定)
- 承诺(已在问题中指定)
- 数组方法:
- 目的:
- .observe()(最初计划用于 ES7,但在2015 年 11 月 2 日完全从规范中删除)
- 。是()
- .setPrototypeOf()
- .getOwnPropertySymbols()
- .getNotifier() (不是 es6,这里的例子)
- .apply() 和 .call() (不是 es6,与 Funciton.prototype.call 和 Function.prototype.apply 的目的相同)
- 数字属性和方法(已在问题中指定)
- 数学方法(很多)(已在问题中指定)
- 常数
I thinks that's all that we have without --harmonyflag.
我认为这就是我们没有--harmony旗帜的全部。
Features with --harmonyflag:
带--harmony标志的功能:
- generators
- arrow functions(without need of
--harmony_arrow_functionsflag in contrast toio.js) - let variables- only in
strict mode - Binary and octal literals
String methods:
- .contains()(was replaced by
includes()in actual ES6 specification) - .startsWith()
- .endsWith()
- .codePointAt()
- .repeat()
- .normalize()
- String.fromCodePoint
- .contains()(was replaced by
Proxy(behind the
--harmony-proxiesflag)
- 发电机
- 箭头函数(
--harmony_arrow_functions与 相比不需要标志io.js) - 让变量- 只在
strict mode - 二进制和八进制文字
字符串方法:
- .contains()(
includes()在实际的 ES6 规范中被替换) - 。以。。开始()
- 。以。。结束()
- .codePointAt()
- 。重复()
- .标准化()
- 字符串.fromCodePoint
- .contains()(
代理(在
--harmony-proxies标志后面)
I think that's all. Maybe if I forgot something - I'll add it later to the list.
我认为仅此而已。也许如果我忘记了什么 - 我稍后会添加到列表中。
回答by pspi
ES6 features trickle down to Node in phases. Node uses Google's V8 as the JavaScript engine. A feature being supported in Node means it first has to be implemented in V8 and then Node team has to incorporate it in Node.js.
ES6 功能分阶段渗透到 Node。Node 使用 Google 的 V8 作为 JavaScript 引擎。Node 支持的特性意味着它首先必须在 V8 中实现,然后 Node 团队必须将它合并到 Node.js 中。
The team at Google releases a new version of V8 roughly every six weeks, and then it's up to the Node team to take it into use.
Google 的团队大约每六周发布一个新版本的 V8,然后由 Node 团队使用它。
Manually curated lists of language features are nice but can become outdated quickly. Node 0.12 is not that in flux anymore, but typically manually curated list becomse obsolete as soon as a new version of Node is rolled out.
手动策划的语言功能列表很好,但很快就会过时。Node 0.12 不再是不断变化的,但通常一旦推出新版本的 Node,手动策划的列表就会过时。
Here are two alternate ways to check what features a Node version supports, without relying on a static list. For further reading and more detailed examples of using these, you can check "How to check if Node.js supports ES 6 language feature"
这里有两种替代方法来检查 Node 版本支持哪些功能,而不依赖于静态列表。有关使用这些的进一步阅读和更详细的示例,您可以查看“如何检查 Node.js 是否支持 ES 6 语言功能”
#1 Easy - compatibility table
#1 简单 - 兼容性表
A dynamically generated list that relies on small tests to confirm the presence of a language feature stays better up to date. One such popular list is kangax.github.io/compat-table/es6/. We are interested only in Node features, so you can use
依赖于小测试来确认语言功能存在的动态生成的列表可以更好地保持最新状态。一个这样的流行列表是 kangax.github.io/compat-table/es6/。我们只对 Node 特性感兴趣,所以你可以使用
that leverages the same data as the kangax site.
它利用与 kangax 站点相同的数据。
#2 Hard - backtrack V8 version
#2 Hard - 回溯 V8 版本
Node uses V8 engine, so determining which version of V8 is included in Node tells us what ES6 language features are supported. You can find out which version of V8 was bundled in Node with node -p process.versions.v8.
Node 使用 V8 引擎,因此确定 Node 中包含的 V8 版本告诉我们支持哪些 ES6 语言特性。您可以找出 Node.js 中捆绑了哪个版本的 V8 node -p process.versions.v8。
$ node -p process.versions.v8
4.6.85.31
Then using Google's V8 project resources you can find which features are implemented in each version. The V8 project keeps an issue trackerwhere you can find ES6+beyond features marked with the harmonylabel.
然后使用 Google 的 V8 项目资源,您可以找到每个版本中实现了哪些功能。V8 项目保留了一个问题跟踪器,您可以在其中找到带有和声标签标记的 ES6+ 之外的功能。

