話の流れを読まずに語るぞ
まず一番Promiseっぽくない使い方だな
function foo() {
Promise.resolve(0)
.then(function(zero) { return 1; })
.then(function(one) { return 2; })
.then(function(two) { return 3; })
.then(function(three) { return 'end'; })
.catch(function(e) { console.log(e) });
console.log('start')
}
最初に実行されるのは start の部分だ。
なぜならPromise.resolveっていうのは内部で
setTimeoutを使っている・・・からだと思えばいい。
そして、Promise.resolve(0)をスタートに、
関数が上から順番に実行されていくわけだ。
戻り値は次の関数の引数になるぞ
ここで言いたいのは、上から順番にthenの中身が実行されていくということだけだ