Skip to content

Instantly share code, notes, and snippets.

@nathggns
Created May 9, 2015 01:01
Show Gist options
  • Save nathggns/8125de8b679a08fb7a87 to your computer and use it in GitHub Desktop.
Save nathggns/8125de8b679a08fb7a87 to your computer and use it in GitHub Desktop.
Explaining dictionary merges
var obj = {
child : {
a : '0',
b : '2'
}
};
var extra = {
b : '3'
};
obj.child = {
// The ... operator "spreads" a dictionary, and as such merges it into the dictionary currently being defined
...(
// This evaluates to the existing nested object, or an empty object if on doesn't exist
obj.child || {}
),
...extra
};
console.log(obj.child.b);
// 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment