前端学习编写的实例
kangkai
2021-04-01 aa5ed6fc701b461f23bd1bf14569bb5025e3b73d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<html>
    <head>        
        <title>Promise</title>
        <script type='text/javascript'>
            var ok = true;
            function successCallBack(){
                console.log("成功");
            };
            function failureCallBack(){
                console.log("失败");
            };
            function successCallBack1(){
                console.log("成功1");
            };
            function failureCallBack1(){
                console.log("失败1");
            };
 
            const wait = ()=> new Promise((resolve,reject)=> {
                setTimeout(() => {
                    console.log('setTimeout1执行完毕');
                    resolve();
                }, 0);                                
            });            
            
            //调用报错,wait2返回的是setTimeout方法。
            const wait1 = ()=> setTimeout(() => {
                console.log('setTimeout2执行完毕');
                return new Promise((resolve,reject)=> {
                    resolve();
                });
            }, 0);
 
            
            var use = wait().then(successCallBack,failureCallBack).then(successCallBack1,failureCallBack1);  
        </script>
    </head>
    <body>
 
    </body>
</html>