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