根据文档,最新的 Node(Node 5+)应默认支持扩展操作符,如下所示:
According to the docs,the latest node (Node 5+) should support the spread operator by default, like so:
const newObj = {
...oldObj,
newProperty: 1
}
我已经安装了Node 5.10.1(例如,'node -v' 命令告诉我),但我仍然遇到了这个错误:
c:\[myprojectfolder]>node index.js
c:\[myprojectfolder]\index.js:21
...oldObj,
^^^
SyntaxError: Unexpected token ...
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:387:25)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:146:18)
at node.js:404:3
我错过了什么?