背景
我有一个非常简单的nodejs应用程序,它使用 Object Destructur Operator of ECMA6
"use strict";
function bananas(){
return {
type: "fruit",
color: "yellow"
};
}
function eat(){
var {
type,
color
} = bananas();
return `I eat ${type} colored ${color}`;
}
console.log(eat());
问题
当我单击index.js的运行按钮时(或者当您右键单击index.js然后选择“运行此文件”时)
我收到以下错误:
Debugger listening on [::]:15454
/home/ubuntu/workspace/server/index.js:16
var {
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.runMain [as _onTimeout] (module.js:441:10)
at Timer.listOnTimeout (timers.js:92:15)
但是,如果我在 bash 命令行中输入 node index.js
我会得到预期的输出:
I eat fruit colored yellow
此外,输入 node -v
输出:
v7.8.0
问题
我坚信运行选项没有选择正确的 Node 版本。 我该如何解决这个问题?
注释
为了更新 Node ,我使用了nvm install 7
。
最佳答案
关于javascript - 如何将 RUN 操作绑定(bind)到 Cloud9 中正确的 NodeJS 版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43089915/