Created
May 2, 2018 20:51
-
-
Save sarahquigley/69d82d7d5ae5b7079c45e743fe4e1350 to your computer and use it in GitHub Desktop.
Example of ES2018 Spread Operator - Copying Object Properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* < 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