0

这是我的 Node.js 脚本:

pDownload("http://serv/file", "localfile")
  .then( ()=> console.log('downloaded file no issues...'))
  .catch( e => console.error('error while downloading', e));

function pDownload(url, dest){} // Yes empty, for now

在 Node.js v0.10.25(Ubuntu 2015.10 上的默认值)上执行时,我收到有关括号的以下语法错误:

/home/nico/main.js:2
  .then( ()=> console.log('downloaded file no issues...'))
          ^
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:902:3

我该如何解决?

4

1 回答 1

-1

Node 0.10 中的 V8 版本不支持箭头函数。

您可以通过以下任一方式修复它:

  • 使用 Babel 之类的东西将代码编译为 ES5
  • 或者使用更新版本的 Node,比如 5.x
  • 使用箭头函数

(感谢詹姆斯·阿拉迪斯)

于 2016-02-10T10:32:22.423 回答