we use ...{}
to join two objects in our project
can anyone explain to me how it works
Thanks
we use ...{}
to join two objects in our project
can anyone explain to me how it works
Thanks
Read about the Object Rest/Spread Properties for ECMAScript:
let a = {a: 1, b: 2};
let b = {b: 3, c: 4};
let c = {...a, ...b};
console.log(c);
It outputs:
{
a: 1,
b: 3,
c: 4
}
See DEMO on JSBin.
Note: It is a Stage 3 proposal for ECMAScript. You need Babel if you want it to work in Node.
This particular syntax that the question asks about is not yet (as of March, 2017) explained in this link that was posted in one of the comments:
because at the time of this writing it is still Stage 3 proposal for ECMAScript. The article on MDN talks only about arrays, for which the spread operator was defined in ES 2015 (ES6) and wasn't changed in ES 2017 so it's nothing new. The syntax for objects, however, is very new and is not even tracked on node.green yet (a website that tracks ES support in Node versions). It is, however, supported by Babel:
so it can be used in Node with transpilation.