Skip to content

Instantly share code, notes, and snippets.

@danielkhan
Created February 11, 2015 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielkhan/0a1ce7ac8129d880807b to your computer and use it in GitHub Desktop.
Save danielkhan/0a1ce7ac8129d880807b to your computer and use it in GitHub Desktop.
// Define some functions and pretend they need to
// be asynchronous just for demonstration purposes
function plus(n1, n2, cb) {
return cb(n1+n2);
}
function minus(n1, n2, cb) {
return cb(n1-n2);
}
function mul(n1, n2, cb) {
return cb(n1*n2);
}
// Let's go to callback hell
plus(42, 17, function(res1) {
minus(res1, 12, function(res2) {
mul(res2, 10, function(res3) {
// Will print out 470
console.log(res3);
})
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment