es6 await函数

await函数

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>await函数</title>

</head>
<body>


<script>

    const p = new Promise((resolve,reject)=>{
        //resolve('成功');
        reject('失败');
    });

    async function fn() {
        try{
            let result = await p;
            console.log(result);
        }catch (e) {
            console.log('error' + e);
        }

    }

    const p2 = fn();
    console.log(p2);
</script>
</body>
</html>
posted @ 2021-06-21 13:05  胡勇健  阅读(105)  评论(0)    收藏  举报