Created
January 17, 2018 11:23
-
-
Save fabriciofmsilva/04068d6d1c05014e6bdd5479f3d7882d to your computer and use it in GitHub Desktop.
Creating a new object that's a combination of others object
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
// 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