-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
The second object was changed when the first is "{}" #14
Comments
Because objects are not cloned, when they are assigned. See the added log at the end: import mixinDeep from "mixin-deep"
const a = {a:{a:1,b:0}};
const b = {a:{b:2},b:1};
const c = {a:{a:2},c:2};
const d = mixinDeep({},a,b,c);
console.log("a",a)
console.log("b",b)
console.log("c",c)
console.log("d",d)
console.log("d.a === a.a", d.a === a.a) I suppose to change Line 29 in 8f464c8
target[key] = mixinDeep({}, val); in case Note: This does not clone arrays. |
Thanks for the reply |
I hit this too and thought it was a bug, but this behaviour is actually specified in the tests. I found this unintuitive and unpredictable, so I created PR 15 to make it work the way I expected. If you need to use my version before Jon merges my pull request, you can install it using the command |
The Code:
The console output:
why "a" is changed,
The text was updated successfully, but these errors were encountered: