Skip to content

Instantly share code, notes, and snippets.

@caius
Created August 6, 2020 21:04
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 caius/1091ca90861d146e85b4b4836900943f to your computer and use it in GitHub Desktop.
Save caius/1091ca90861d146e85b4b4836900943f to your computer and use it in GitHub Desktop.
// 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