Created
August 6, 2020 21:04
-
-
Save caius/1091ca90861d146e85b4b4836900943f 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
// Callback hell approach | |
function main() { | |
console.log("hello from main") | |
var name = "caius" | |
sendHello(decorateName(name)) // <- smelly | |
} | |
function decorateName(name) { | |
return `Prof. ${name}` | |
} | |
function sendHello(name) { | |
console.log(`Why hello ${name}`) | |
} | |
main() | |
// Promises approach | |
new Promise(function(next, reject) { | |
var name = "caius" | |
next(name) | |
}).then(function(name) { | |
new Promise(function(next, reject) { | |
var decorated = `Prof. ${name}` | |
next(decorated) | |
}) | |
}).then(function(name){ | |
console.log(`Why hello ${name}`) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment