Last active
February 29, 2024 15:51
-
-
Save sheldonh/6089299 to your computer and use it in GitHub Desktop.
CoffeeScript Object.merge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' } | |
### |
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
@alexbfree Semicolons are fully optional in CS. (
console.log "hi"
andconsole.log "hi";
are both 100% valid), but they are still the only way to fit multiple statements on the same line.To quote the coffeescript website directly:
"You don’t need to use semicolons ; to terminate expressions, ending the line will do just as well (although semicolons can still be used to fit multiple expressions onto a single line)." (source)