async 和 await 原

async和await的使用

async

async 异步执行  

用法:

async function name () {
    return 'hello'
}

console.log(name())

console.log('world')

async 后面的函数的执行不会阻碍后面console的执行,两个语句是同时执行的。

await

await 同步执行

用法:

await function name () {
    return 'hello'
}

console.log(name())

console.log('world')

await 后面的函数执行完了才能执行后面的语句。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章