問題:下面四個使用 promise 的語句之間的不一樣點在哪兒?promise
doSomething().then(function () { return doSomethingElse(); }); doSomethin().then(function () { doSomethingElse(); }); doSomething().then(doSomethingElse()); doSomething().then(doSomethingElse);
經過本身跑下測試代碼,才發現不一樣的地方:測試
1 doSomething().then(function () { 2 return doSomethingElse(); 3 }).then(function(result){ 4 console.log(result); //輸出doSomethingElse()中所返回的Promise.resolve() 5 }); 6 7 doSomething().then(function () { 8 doSomethingElse(); 9 }).then(function(result){ 10 console.log(result); //輸出undefined 11 }); 12 13 doSomething().then(doSomethingElse()).then(function(result){ 14 console.log(result); //輸出doSomething()中所返回的Promise.resolve() 15 }); 16 17 doSomething().then(doSomethingElse).then(function(result){ 18 console.log(result); //輸出doSomethingElse()中所返回的Promise.resolve() 19 });