Skip to content

Instantly share code, notes, and snippets.

@stefanfrede
Created August 3, 2016 05:28
Show Gist options
  • Save stefanfrede/57e659352179729bea207a3e5ad155a5 to your computer and use it in GitHub Desktop.
Save stefanfrede/57e659352179729bea207a3e5ad155a5 to your computer and use it in GitHub Desktop.
Extend objects by assigning properties.
// 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