I've been using this extend:
const extend = require('util')._extend;
but just noticed it modifies the original object:
> let hello = {a: 5};
> extend(hello, {poop: 'whas'})
{ a: 5, poop: 'whas' }
> hello
{ a: 5, poop: 'whas' }
What's a concise way I can extend objects without modifying them?
E.g. I'd want the above repl session to look like:
> let hello = {a: 5};
> extend(hello, {poop: 'whas'})
{ a: 5, poop: 'whas' }
> hello
{ a: 5 }
extendfunctions extend their first argument. You are looking for a copy function it seems.extend({}, hello, {poop: 'whas'})extends a new object (the object literal) nothello.