Last active
March 26, 2020 15:09
-
-
Save unionx/a40129735f849cdd8d52130c8bed7a4a to your computer and use it in GitHub Desktop.
JS promise
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
function foo() { | |
let p = new Promise(function(resolve, reject) { | |
setTimeout(function() { | |
console.log('foo'); | |
resolve('foo111'); | |
}, 1000); | |
}); | |
return p; | |
} | |
function bar() { | |
console.log('bar'); | |
return 'bar111'; | |
} | |
function foobar(x) { | |
console.log(x); | |
} | |
let out = foo() | |
.then(function() { | |
return bar(); | |
}) | |
.then(function(x) { | |
foobar(x); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment