简体   繁体   English

在Node.JS中使用ECMAScript 6

[英]Using ECMAScript 6 In Node.JS

I'm sure this is a simple one - But I'm learning Javascript and executing programs through Node.js 我确信这是一个简单的 - 但我正在学习Javascript并通过Node.js执行程序

function sumAll(arr) {

   var max = Math.max(...arr);
   console.log(max);

}

sumAll([1, 4]);

The error I have is: 我遇到的错误是:

SyntaxError: Unexpected token ... SyntaxError:意外的令牌......

I assume this is down to the ES6 spread operator? 我假设这是由ES6传播运营商决定的? Is this not valid? 这不是有效的吗?

I have also tried to add the following, based on other StackOverflow answers I've found: 我还尝试添加以下内容,基于我发现的其他StackOverflow答案:

"use strict";

But this doesn't work either. 但这也不起作用。

Any help appreciated - Thanks 任何帮助表示感谢 - 谢谢

Seems that you use outdated node.js version. 似乎您使用了过时的node.js版本。 Try to update your node.js to the latest version. 尝试将node.js更新到最新版本。

Might be you are using outdated node.js version. 你可能正在使用过时的node.js版本。 Try to update your node.js with v6.10 or later on the latest version. 尝试使用最新版本的v6.10或更高版本更新node.js.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM