3 ms·
If something is immutable then you never need to clone it. Just copy the reference. If an object is immutable and you want to copy/mutate one item it then you
by quickthrower2 3y ago
If something is immutable then you never need to clone it. Just copy the reference.
If an object is immutable and you want to copy/mutate one item it then you can surgically clone it in O(how deeply nested the item to change is). Object spread being the simple case.
JS makes this messy to do though! Lots of spreads and array maps or you pull in a library like Immer and now have “coloured” objects. Immutability in JS is not idiomatic so for that reason I try to avoid unless I really need to.