Node v6 failing on object spread

ecmascript-6, node.js

Solution

Looks like ES6 spread operator only works for arrays and iterables. It is specifically designed to NOT WORK for objects: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Spread_operator

Relevant quote:

Only apply for iterables

var obj = {"key1":"value1"};
function myFunction(x) {
    console.log(x); // undefined
}
myFunction(...obj);
var args = [...obj];
console.log(args, args.length) //[] 0

Though the MDN article previously suggested that trying to use the spread operator on objects should result in undefined instead of throwing an error. As of this revision, the current MDN article discusses support for "Spread for object literals"

Additionally the node.js compatibility table claims node.js fully comply with the specification of the spread operator with arrays and iterables, but specifically indicates that object rest/spread properties are not supported: http://node.green/#ESNEXT-candidate--stage-3--object-rest-spread-properties, at least not until Node version 8.60 (at which point the color turns green to indicate that beginning in 8.3, Node does support the object spread/rest operator, as pointed out in the other answer)

Problem

I had a question about why node v6.7 would be failing to run this code: ``` var a = { foo: 'bar' } var b = { ...a, my: 'sharona' } console.log(b) ``` Anyone have an idea why that would be? I thought v6 supported object spreading..? But I guess not? Here is the error I'm seeing: ``` /home/teselagen/ve/tnrtest.js:6 ...a, ^^^ SyntaxError: Unexpected token ... at Object.exports.runInThisContext (vm.js:76:16) at Module._compile (module.js:528:28) at Object.Module._extensions..js (module.js:565:10) at Module.load (module.js:473:32) at tryModuleLoad (module.js:432:12) at Function.Module._load (module.js:424:3) at Module.runMain (module.js:590:10) at run (bootstrap_node.js:394:7) at startup (bootstrap_node.js:149:9) at bootstrap_node.js:509:3 ```

Original source