[ lodash ] _.extend(destination, source) v.s. _.merge(destination, source)

TL;DR;

merge will merge object hierarchy from source to destination. While for extend/assign, it’s simple one level copy of properties from source to destination.

 

extend/assign

For each property in source, copy its value as-is to destination. if property values themselves are objects, there is no recursive traversal of their properties. Entire object would be taken from source and set in to destination.

merge

For each property in source, check if that property is object itself. If it is then go down recursively and try to map child object properties from source to destination.

ref : https://stackoverflow.com/questions/19965844/lodash-difference-between-extend-assign-and-merge,

https://makandracards.com/makandra/29599-underscore-lodash-how-to-extend-or-merge-into-a-new-object

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s