So today I just discovered the
_.extends function of underscore. There’s a little known function that is similar, called
_.extendsOwn. This basically is the underscore version for the upcoming ‘Object.assign’ method of ES6.
Long story cut short - I wanted more info about these functions which led me to this article:
There’s this method that is very similar to extend, called
_.defaults that is really useful. Imagine you have an existing object that you dont want certain properties (and their values) to be overwritten when merging other objects into it. That’s what defaults are for basically. Any present values in the existing object wont get overwritten by other object’s attributes.
The use cases are for the times that you want to exclude certain properties when merging together objects. One application is pushing data to an incrementing indexing NoSQL database that absolutely must have the same identifier in the JSON message, to be able to search for it later.
So cool. For more info on extend, checkout this 2ality article