Last active
December 21, 2015 11:18
-
-
Save sukima/6297570 to your computer and use it in GitHub Desktop.
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
get = -> | |
secret_callback = ( ()-> ) | |
secret_squirrly_function = ( ()-> secret_callback(err, res, body) ) | |
# Do something asynchronous | |
setTimeout(secret_squirrly_function, 5000) | |
# and return a function | |
return ( | |
(callback) -> | |
secret_callback = callback | |
) | |
returned_function = get() | |
returned_function( | |
(err, res, body) -> | |
console.log "Done!" | |
) |
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
function get() { | |
var secret_callback = function() { }; | |
var secret_squirrly_function = function() { | |
return function() { secret_callback(err, res, body); }; | |
}; | |
// Do something asynchronous | |
setTimeout(secret_squirrly_function, 5000); | |
// and return a function | |
return function(callback) { | |
secret_callback = callback; | |
}; | |
} | |
returned_function = get(); | |
returned_function( | |
function(err, res, body) { | |
console.log "Done!"; | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment