Created
July 18, 2011 12:13
-
-
Save thejh/1089339 to your computer and use it in GitHub Desktop.
getUser example for method overloading example
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
getUser = (*) -> | |
(name) when typeof name is 'string' -> | |
User.lookup 'name', name | |
(id) when typeof id is 'number' -> | |
User.lookup 'id', id | |
-> | |
throw new Error "invalid arguments" |
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
getUser = function() { | |
if ((function(name) { | |
return typeof name === 'string'; | |
})(arguments[0])) { | |
return (function(name) { | |
return User.lookup('name', name); | |
})(arguments[0]); | |
} else if ((function(id) { | |
return typeof id === 'number'; | |
})(arguments[0])) { | |
return (function(id) { | |
return User.lookup('id', id); | |
})(arguments[0]); | |
} else { | |
throw new Error("invalid arguments"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment