Skip to content

Instantly share code, notes, and snippets.

Created November 26, 2015 05:09
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 anonymous/2b1915f6e484fd7c6ed8 to your computer and use it in GitHub Desktop.
Save anonymous/2b1915f6e484fd7c6ed8 to your computer and use it in GitHub Desktop.
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