Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sarahquigley/69d82d7d5ae5b7079c45e743fe4e1350 to your computer and use it in GitHub Desktop.
Save sarahquigley/69d82d7d5ae5b7079c45e743fe4e1350 to your computer and use it in GitHub Desktop.
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