Is there any way to get Underscore.js extend function:
Copy all of the properties in the source objects over to the destination object, and return t
Kurt Milam has published a mixin that adds a deepExtend method to underscore.js. It even deals with regular expressions (if you want). Excerpt from the documentation:
Mix it in with underscore.js:
_.mixin({deepExtend: deepExtend});Call it like this:
var myObj = _.deepExtend(grandparent, child, grandchild, greatgrandchild)Notes: Keep it DRY.
This function is especially useful if you're working with JSON config documents. It allows you to create a default config document with the most common settings, then override those settings for specific cases. It accepts any number of objects as arguments, giving you fine-grained control over your config document hierarchy.