乐趣区

浏览器事件循环和我的头发

        btn.addEventListener("click", event => {setTimeout(() => {console.log("S1")}, 0)
            Promise.resolve().then(() => console.log("M1"))
            console.log("L1")
        })
        btn.addEventListener("click", event => {setTimeout(() => {console.log("S2")}, 0)
            Promise.resolve().then(() => console.log("M2"))
            console.log("L2")
        })

点击 btn
输出:L1、M1、L2、M2、S1、S2
大家都很聪明,应该都理解!

        btn.addEventListener("click", event => {setTimeout(() => {console.log("S1")}, 0)
            Promise.resolve().then(() => console.log("M1"))
            console.log("L1")
        })
        btn.addEventListener("click", event => {setTimeout(() => {console.log("S2")}, 0)
            Promise.resolve().then(() => console.log("M2"))
            console.log("L2")
        })
        btn.click()

输出:L1、L2、M1、M2、S1、S2

退出移动版