Figuring out Object spread (ES2015)

Why is that useful for Redux’s immutable state? I was trying to figure it out then I understood that spread will copy all the enumarable properties in to the new object from the target.

//Enumarable properties
let person = Object.assign({}, {name: 'Joe', age: 12});

//Non-enumarable property
Object.defineProperty(person, 'profession', {value: 'preacher', enumarable: false});
console.log(person, Object.keys(person));

//Using Object spread to copy enumarable props only
let newObject = {...person, anotherProp: 'Hello'};

Leave a Reply