JavaScript開發之--.then()方法


 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()內部的程序,這樣就避免了,數據沒獲取到等的問題

 

僅做記錄!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM