Created
July 19, 2018 03:01
-
-
Save SamanShafigh/50e92228d94ed9b0e71dddae89e606e0 to your computer and use it in GitHub Desktop.
async using callback
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
// Async using call back | |
var addA = function (a, b, cb) { | |
setTimeout (() => { | |
cb(a + b); | |
}, 0); | |
}; | |
// How to use it :D | |
addA(2, 3, (result) => { | |
console.log(result) | |
}) | |
// Callback Hell :( | |
addA(1, 1, (r) => { | |
addA(r, 1, (r) => { | |
addA(r, 1, (r) => { | |
addA(r, 1, (r) => { | |
addA(r, 3, (r) => { | |
addA(r, 3, (r) => { | |
console.log(r) | |
}) | |
}) | |
}) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment