8000 When merging modified primitive type objects, added properties get dropped · Issue #2008 · lodash/lodash · GitHub
[go: up one dir, main page]

Skip to content

When merging modified primitive type objects, added properties get dropped #2008

New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
codingmatty opened this issue Feb 16, 2016 · 4 comments
Closed

Comments

@codingmatty
Copy link

Bug when using v4.4.0
We use a pattern where we add properties to a string object. When we try to merge that string property into another object, all the properties originally added are dropped.
I'm not sure if this is specifically an issue with merge, or if other functions are affected.

> var testStr = new String('testStr');
> testStr.prop1 = 'testStr.prop1'
> testStr
{ [String: 'testStr'] prop1: 'testStr.prop1' }

// It seems to work 1 level deep.
> _.merge({}, { testStr: testStr })
{ testStr: { [String: 'testStr'] prop1: 'testStr.prop1' } }

// but any deeper and it doesn't work as expected.
> _.merge({}, { testStr: { testStr: testStr } })
{ testStr: { testStr: [String: 'testStr'] } }
@jdalton
Copy link
Member
jdalton commented Feb 16, 2016

This is a lodash wide behavior. When cloning or comparing boolean, number, & string objects any added properties are ignored. The use of those is so rare that I could see putting them down the plain object path.

@codingmatty
Copy link
Author

This behavior seemed to change from 4.3 to 4.4, why might that have changed between minor versions?

@jdalton
Copy link
Member
jdalton commented Feb 16, 2016

Our clone/equality behavior did not change between 4.3 and 4.4. We did fix an issue where we weren't cloning a value properly which may be what you're seeing. Lodash has never supported expando properties on the object form of primitives.

I'll add support for it though. It'll slow those paths down but they aren't used nearly as often as arrays and plain objects so it's cool.

jdalton added a commit that referenced this issue Feb 17, 2016
jdalton added a commit that referenced this issue Feb 17, 2016
@lock
Copy link
lock bot commented Jan 19, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants
0