4 ms·
Cloning is fairly common when you're writing functional style code with immutable objects. Not "code smell".
by DrJokepu 4y ago
Cloning is fairly common when you're writing functional style code with immutable objects. Not "code smell".
- fnordsensei 4y agoBut when you’re using immutable data, deep cloning is not something you need for to worry about. So it kind of is an anti-pattern in this case.
- DrJokepu 4y agoCopy-on-write is a common operation on immutable data and deep cloning is how you do that in JavaScript in a safe manner.
- deleted 4y ago[deleted]
- fnordsensei 4y agoOh yeah, that’s true. I was thinking of RRB trees, hash array mapped tries and things like this.
- gloryjulio 4y agoBut if you are doing more functional style, you would be copying the reference, NOT the object. Functional style makes you need LESS of deep copy. See immerjs Also your object won't be that complicated in the first place, they would be treated as plain data object like struct or record. And you would not use those advanced features in objects(Not needed).