Created
March 18, 2013 23:30
-
-
Save aseemk/5191967 to your computer and use it in GitHub Desktop.
Sexy method argument overloading in CoffeeScript.
This file contains hidden or 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
# | |
# Overloads: | |
# - fetch(url, callback) | |
# - fetch(url, opts, callback) | |
# | |
fetch = (args...) -> | |
[arg0, arg1, arg2] = args | |
[url, opts, callback] = switch args.length | |
when 0, 1 then throw new Error "Usage: fetch(url[, opts], callback)" | |
when 2 then [arg0, null, arg1] | |
else [arg0, arg1, arg2] | |
# ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment