underscore mixin deepExtend
Copy all of the properties in the source objects over to the destination object, and return the destination object. This method will recursively copy mutual properties which are also objects.
Original code: https://gist.github.com/ElliotChong/3861963
How to use
var user = {
"name": {
"first": "Earl"
},
"friends": ["0", "1", "3"],
"job": "Mad Scientist",
"pets": { "dog": "Ralph" }
};
var userUpdate = {
"name": {
"last": "Duncan"
},
"friends": ["6", "9"],
"job":
"Happy Scientist",
"pets": {
"cat": "Judy"
},
"city": "Portlandia"
};
_.deepExtend(user, userUpdate);
/*
results in user equalling:
{
"name": {
"first": "Earl",
"last": "Duncan"
},
"friends": ["0", "1", "3", "6", "9"],
"job":
"Happy Scientist",
"pets": {
"dog": "Ralph", "cat": "Judy"
},
"city": "Portlandia"
}
*/
License
Licensed under the MIT License and WTFPL License.