Created
February 11, 2015 02:03
-
-
Save danielkhan/0a1ce7ac8129d880807b to your computer and use it in GitHub Desktop.
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
// 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