Skip to content

Instantly share code, notes, and snippets.

@fabriciofmsilva
Created January 17, 2018 11:23
Show Gist options
  • Save fabriciofmsilva/04068d6d1c05014e6bdd5479f3d7882d to your computer and use it in GitHub Desktop.
Save fabriciofmsilva/04068d6d1c05014e6bdd5479f3d7882d to your computer and use it in GitHub Desktop.
Creating a new object that's a combination of others object
// Creating a new object that's a combination of
// `state` and `changes` objects.
// Old JavaScript:
var newState = {};
[state, changes].forEach(function(obj) {
for (var propName in obj) {
if (obj.hasOwnProperty(propName)) {
newState[propName] = obj[propName];
}
}
});
// Modern JavaScript
const newState = { ...state, ...changes };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment