Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

_.merge modifies source object #77

Closed
engram-design opened this Issue Sep 27, 2012 · 6 comments

Comments

2 participants

This might be expected behaviour, but when using var new_object = _.merge(source, opts), opts will update both source and new_object with its values.

The issue is better illustrated here:

http://jsfiddle.net/WPRcF/2/

Owner

jdalton commented Sep 27, 2012

Nope, that's a bug. Thanks!

Owner

jdalton commented Sep 27, 2012

Sorry, I misread the issue. This is the desired behavior. Your jsfiddle can be tweaked to work by using the deep clone option: http://jsfiddle.net/WPRcF/3/

@jdalton jdalton closed this Sep 27, 2012

Owner

jdalton commented Sep 27, 2012

In your example the new_object is the source object as _.merge returns the source object.
See http://lodash.com/docs/#merge

D'oh! Didn't realise there was a deep option for clone... Thanks!

Owner

jdalton commented Sep 27, 2012

No prob. Keep in mind deep clone is unique to Lo-Dash so if you build Lo-Dash with the underscore modifier (ex: lodash underscore), it will be swapped with Underscore's shallow clone.

Yep, good point. Thanks again mate!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment