Node.js 0.12 中提供的 ECMAScript 6 功能 [英] ECMAScript 6 features available in Node.js 0.12
问题描述
Node.js (0.12) 的新稳定版本最近发布,其中包含升级的 Google v8 JavaScript 引擎 v3.28.73.
A new stable release of Node.js (0.12) has landed recently with an upgraded Google's v8 JavaScript engine, v3.28.73.
我检查了几个声称列出 ES 6 特性的网站,但它们似乎都过时了——最突出的是,此表(更新:现在更新为 0.12 的当前 Node.js 状态),因为列出了一些功能因为需要 --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 --harmony
flag while I found some of them being enabled by default (Maps, Sets, Symbols, to name a few). Update: Node specific tables have since been made available
此外,试图纯粹为 v8 引擎搜索这些信息会提供过于最新的信息 - 当前的 v8 版本是 4.2.*,这远远领先于 Node.js 使用的版本.
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.
我希望这个问题(及其答案)能够成为对 Node.js 开发人员现在可以使用的 ES 6 功能的全面总结.
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.
- Maps、Sets/WeakMaps、WeakSets
- 符号
- Object.observe
- 承诺
- 号码
- .isInteger
- .isSafeInteger
- .isNaN
- .EPSILON
- .MIN_SAFE_INTEGER
- .MAX_SAFE_INTEGER
- .clz32
- .imul
- .sign
- .log10
- .log2
- .log1p
- .expm1
- .cosh
- .sinh
- .tanh
- .acosh
- .asinh
- .atanh
- .trunc
- .fround
- .cbrt
- .hypot
推荐答案
没有
--harmony
标志的特性:Features without
--harmony
flag:- "for-of" 循环
- 地图、设置,WeakMap, WeakSet(已在问题中指定)
- 符号(已在问题中指定)
- Promise(已在问题中指定)
- 数组方法:
- "for-of" loop
- Map, Set, WeakMap, WeakSet (already specified in question)
- Symbol (already specified in question)
- Promise (already specified in question)
- Array methods:
- .keys()
- .values()
- .entries()
- [Symbol.iterator]
- .observe()(最初是为 ES7 计划,但于 2015 年 11 月 2 日完全从规范中删除)
- .is()
- .setPrototypeOf()
- .getOwnPropertySymbols()
- .getNotifier()(不是 es6,示例此处)
- .apply() 和 .call()(不是 es6,与 Funciton.prototype.call 和 Function.prototype.apply 的目的相同)
我认为这就是没有
--harmony
标志的我们所拥有的一切.I thinks that's all that we have without
--harmony
flag.带有
--harmony
标志的功能:Features with
--harmony
flag:- generators
- arrow functions (without need of
--harmony_arrow_functions
flag in contrast toio.js
) - let variables - only in
strict mode
- Binary and octal literals
String methods:
- .contains()(在实际的 ES6 规范中被
includes()
取代) - .startsWith()
- .endsWith()
- .codePointAt()
- .repeat()
- .normalize()
- String.fromCodePoint
- .contains() (was replaced by
includes()
in actual ES6 specification) - .startsWith()
- .endsWith()
- .codePointAt()
- .repeat()
- .normalize()
- String.fromCodePoint
代理(在后面
--harmony-proxies
标志)我认为仅此而已.也许如果我忘记了什么 - 我稍后会添加到列表中.
I think that's all. Maybe if I forgot something - I'll add it later to the list.
这篇关于Node.js 0.12 中提供的 ECMAScript 6 功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!