Created
November 26, 2015 05:09
-
-
Save anonymous/2b1915f6e484fd7c6ed8 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
let aaa = () => { | |
return new Promise((resolve, reject) => { | |
console.log('aaa '); | |
resolve('from_aaa'); | |
}); | |
}; | |
let bbb = (value) => { | |
return new Promise((resolve, reject) => { | |
console.log('bbb ' + value); | |
resolve('from_bbb'); | |
}); | |
}; | |
let ccc = (value) => { | |
return new Promise((resolve, reject) => { | |
console.log('cccc ' + value); | |
resolve('from_ccc'); | |
}); | |
}; | |
// -- code execute | |
aaa() | |
.then((value) => { | |
// do nothing with value coming from aaa | |
return bbb( 123 ); // call bbb() with custom parameter | |
}) | |
.then( ccc ); | |
/* results: | |
aaa | |
bbb 123 | |
ccc from_bbb | |
*/ | |
// -- trying to write it shorter... | |
aaa() | |
.then( bbb(123) ) | |
.then( ccc ); | |
/* results: | |
aaa | |
bbb 123 <-- this worked but the next one | |
ccc from_aaa <-- this didn't, it grabbed | |
the value returned from aaa() instead of bbb() | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment