1 <script> 2 new Promise(function (resolve,reject) { 3 setTimeout(function () { 4 console.log('First'); 5 resolve(); 6 },1000); 7 }).then(function () { 8 return new Promise(function (resolve,reject) { 9 setTimeout(function () { 10 console.log("Second"); 11 resolve(); 12 },4000); 13 }); 14 }).then(function () { 15 setTimeout(function () { 16 console.log("Third"); 17 },3000); 18 }); 19 </script>
.then()方法是異步執行;當.then()前的方法執行完后再執行then()內部的程序,這樣就避免了,數據沒獲取到等的問題
僅做記錄!