Skip to content

Instantly share code, notes, and snippets.

@sheldonh
Last active February 29, 2024 15:51
Show Gist options
  • Save sheldonh/6089299 to your computer and use it in GitHub Desktop.
Save sheldonh/6089299 to your computer and use it in GitHub Desktop.
CoffeeScript Object.merge
merge = (xs...) ->
if xs?.length > 0
tap {}, (m) -> m[k] = v for k, v of x for x in xs
tap = (o, fn) -> fn(o); o
console.log merge {foo: '1', bar: 'baz'}, {bar: 'bis'} , {wombat: 'fishpaste'}
###
{ foo: '1', bar: 'bis', wombat: 'fishpaste' }
###
@sixtyfive
Copy link

The version by @bogdan (23 Nov 2015) unfortunately doesn't compile for me. The original version works fine, though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment