r/backtickbot • u/backtickbot • Feb 17 '21
https://np.reddit.com/r/learnjavascript/comments/llau8d/javascript_object_merge/gnqkqzi/
Nice, my only criticism is if you are at all concerned with prototypes. Hopefully we're in the land of functional patterns by now, but lots of projects still use OOP.
Just add one part to that merge function...
const protoA = Object.getPrototypeOf(a);
const protoB = Object.getPrototypeOf(b);
const proto = { ...protoA, ...protoB };
const obj = Object.create(proto, a);...or something like that. Forgive me, it's late and I'm not testing this atm.
1
Upvotes