Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of ES2018 Spread Operator - Copying Object Properties
/* < ES2018 */
var coat = { color: 'tabby', mittens: true };
var catMaru = Object.assign({ name: 'Maru', likes: 'boxes'}, coat);
// > { name: 'Maru', likes: 'boxes', color: 'tabby', mittens: true }
/* >= ES2018 */
var coat = { color: 'tabby', mittens: true };
var catMaru = { name: 'Maru', likes: 'boxes', ...coat };
// > { name: 'Maru', likes: 'boxes', color: 'tabby', mittens: true }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment