:::info ES7的新玩意,觉得promise还是在回调,弄了个这个加深了一下promise,很不错 :::

    1. async function f(){
    2. console.log(1)
    3. let r = await new Promise(function (res) {
    4. setTimeout(function () {
    5. res(3)
    6. }, 1000)
    7. })
    8. console.log(r)
    9. console.log(4)
    10. }
    11. // 区域外依然是异步的
    12. console.log(2)
    13. // 1
    14. // 2
    15. // 3
    16. // 4
    17. //如果异步操作返回 1 4 2 3