Grabbed jQuery's extend method, and made it library agnostic.
Gist: Library agnostic version of jQuery's Extend
Its wrapped in an Extender constructor, so you don't have to instantiate
all of its internal methods each time you call the extend method.
Disclaimer: I have not tested this extensively. It's basically a 1:1 clone of jQuery's extend(), however your mileage may vary.
Use it like this.
var user1 = {
name: "user1",
settings: {
first: "1",
second: {bar: 'foo'}
}
};
var user2 = {
name: "user2",
settings: {
second: {foo:'bar'}
}
};
/* merge user1 into User */
__extend(true, user1, user2);
// Modifies the User object
user1.settings.second.foo == 'bar'; // true
// note, you can do assignment too.
var newUser = __extend(true, user1, user2);
See here for more documentation