Adr*_*ran 12 node.js ecmascript-harmony arrow-functions
我试图用箭头功能node v0.10.33下Ubuntu 14.04(我运行与节点--harmony标志),但我得到这个错误:
console.log( [1,2,3,4].map(x => x*x) );
^
SyntaxError: Unexpected token >
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3
Run Code Online (Sandbox Code Playgroud)
现在应该在节点v0.12.x中使用该--harmony标志.另请注意,您可以使用babel程序包在节点中获取箭头功能.
http://babeljs.io/docs/using-babel/
更新:
正如Mike'Pomax'Kamermans正确指出的那样,--harmony使用Node.js> = 4.x时不需要该标志.有关Node.js中ES6支持状态的更多信息,请参阅https://nodejs.org/en/docs/es6/.
Node,即使有和声标志,也不支持粗箭头。来源。
编辑:有趣的小事实,ES6 支持是 Node 分叉到 io.js 的原因之一。查看他们关于 ES6 特性的页面——他们为箭头函数提供了一个标志,但不鼓励使用它。
| 归档时间: |
|
| 查看次数: |
7048 次 |
| 最近记录: |