Created
August 3, 2016 05:28
-
-
Save stefanfrede/57e659352179729bea207a3e5ad155a5 to your computer and use it in GitHub Desktop.
Extend objects by assigning properties.
This file contains hidden or 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
// Copy an object by extending an empty object: | |
Object.assign({}, { | |
apples: 12, | |
oranges: 12 | |
}) | |
//=> { apples: 12, oranges: 12 } | |
// Extend one object with another: | |
const inventory = { | |
apples: 12, | |
oranges: 12 | |
}; | |
const shipment = { | |
bananas: 54, | |
pears: 24 | |
} | |
Object.assign(inventory, shipment) | |
//=> { apples: 12, | |
// oranges: 12, | |
// bananas: 54, | |
// pears: 24 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment