r/programminghorror • • Apr 30 '26
Javascript Cursed use of object spread
Using object spread to append values to an object in the form of another object
86
Upvotes
r/programminghorror • • Apr 30 '26
Using object spread to append values to an object in the form of another object
2
u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” May 01 '26
There is no way those last two don't overflow, is there?
35
u/ironykarl Apr 30 '26
This is idiomatic, if you're trying to update objects in an immutable way.I definitely dislike the formatting, because I feel like it obscuresOkay, the spread on the newly-created/anonymous object is completely pointless.
What this should look like is:
14
u/oweiler Apr 30 '26
I mean yes, but programminghorror?
3
u/BlackFuffey Apr 30 '26
why
1
u/scmkr Apr 30 '26
Isn’t this just how it’s done in JS?