Let us take one such scenario and create a new function
$upsert which mutates an array and update a given object in array based on passed criterion.
This is a common scenario and to use this, we may have to create a function such as below and call it everytime using
_.mixinA much better way is to add this method being called as part of the lo-dash library and use it on
_object. Lo-dash provides a method
_.mixinfor this. Let us see how we can use the above code to create the mixin and use it conveniently and even on function chains.
That's it! Using the same
_.mixin method we can even decorate/ augment existing library methods. But, we should be cautious in doing so as it may have unwanted side-effects
on parts of our code.