Created
December 19, 2011 06:19
-
-
Save jed/1495681 to your computer and use it in GitHub Desktop.
recursive IIFEs
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
upperCase = (str, cb) -> | |
do fn = (err, str) -> | |
if err | |
cb err | |
else if typeof str is 'function' | |
str fn # fn is this function, as of 1.2.1-pre | |
else | |
str = String str | |
cb null, str.toUpperCase() |
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
upperCase = function(str, cb) { | |
var fn; | |
return (fn = function(err, str) { | |
if (err) { | |
return cb(err); | |
} else if (typeof str === 'function') { | |
return str(fn); | |
} else { | |
str = String(str); | |
return cb(null, str.toUpperCase()); | |
} | |
})(err, str); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
here's how i'd write it in javascript: