Skip to content

Instantly share code, notes, and snippets.

@sukima
Last active December 21, 2015 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sukima/6297570 to your computer and use it in GitHub Desktop.
Save sukima/6297570 to your computer and use it in GitHub Desktop.
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!"
)
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