Better HN
top
new
best
ask
show
jobs
Log in
Sign up
Better HN
Comment
by
taco_emoji
· 8y ago · 0 comments
Why is deep copy so essential? Deep copy is the wrong solution to your problem 99% of the time, IMO.
Comments
[–]
frwhlr
8y ago
I think spamming mutable objects around in your codebase is asking for trouble. I'd be really happy to be able to do something like this:
foo( Object.copy(barObj) );
I mean, why would you send your state's mutable object as argument if you're 100% sure you don't want it to be changed?
[–]
taco_emoji
OP
8y ago
Because copying is expensive. If mutability is the issue, use Object.freeze(), or define properties with Object.defineProperty() setting
writable
to false.