es7 async await

async 修饰函数 默认返回一个Promise对象 await后是一个Promise对象并且await只能用于async函数中

var fun = async function() {
               return 'aaaaa'
        }
        console.log(fun())//Promise {<resolved>: "aaaaa"}
        fun().then(res => {
            console.log(res)//'aaaaa'
        })
        async function fun1() {
            var ret = await fun();
            console.log(ret)//'aaaaa'
        }
        fun1()

  

  

posted @ 2020-05-22 16:59  howhy  阅读(59)  评论(0)    收藏  举报