In object literals we can use the spread operator (...) it inserts properties from a given object, to the object literal...
so if you have:
const a = {
foo: 'bar',
test: 'test'
}
A new object can be created using the spread operator in the object literal definition..
const b = {
...a, //spread operator that introduces object properties
foo:'bla'
}
The b object would be
{ foo: 'bla', test: 'test' }
Take in to account that the if two properties have the same name, the order will define which one takes priority and indeed we can overwrite a property definition in the object literal.
if the definition was:
const b = {
foo:'bla',
...a, //the spread operator is defined at the end
}
The b object will be:
{foo: "bar", test: "test"}
Refer to this article
Note: This is a ES2018 proposal, currently working in chrome..