MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/btxz72/what_are_some_javascript_things_beginners_dont/ep79zf2
r/javascript • u/[deleted] • May 28 '19
383 comments sorted by
View all comments
Show parent comments
3
You're right. It should be
const obj2 = Object.assign({}, obj1)
1 u/johnslegers May 29 '19 Even Object.assign can be tricky when you have nested objects!See https://repl.it/repls/FloralwhiteGruesomeSystemcall 1 u/tomius May 29 '19 Yeah, yeah. I use deep copy in those cases. Or do it manually if it's not too much. Specially tricky when using redux. 1 u/johnslegers May 29 '19 Aren't you supposed to use immutable data types in Redux to avoid this trickiness?
1
Even Object.assign can be tricky when you have nested objects!
See https://repl.it/repls/FloralwhiteGruesomeSystemcall
1 u/tomius May 29 '19 Yeah, yeah. I use deep copy in those cases. Or do it manually if it's not too much. Specially tricky when using redux. 1 u/johnslegers May 29 '19 Aren't you supposed to use immutable data types in Redux to avoid this trickiness?
Yeah, yeah. I use deep copy in those cases. Or do it manually if it's not too much. Specially tricky when using redux.
1 u/johnslegers May 29 '19 Aren't you supposed to use immutable data types in Redux to avoid this trickiness?
Aren't you supposed to use immutable data types in Redux to avoid this trickiness?
3
u/tomius May 28 '19
You're right. It should be
const obj2 = Object.assign({}, obj1)