[JavaScript] 纯文本查看 复制代码
const testElement = document.getElementById('testElement')setTimeout(() => { console.log(performance.now(), 'settimeout')}, 0)requestAnimationFrame(() => { console.log(performance.now(), 'requestAnimationFrame')})var observer = new MutationObserver(() => { console.log('MutationObserver')});observer.observe(testElement, { childList: true })const div = document.createElement('div')testElement.appendChild(div)new Promise(resolve => { console.log('promise') resolve()}).then(() => console.log('then'))console.log(performance.now(), 'global')
在浏览器的输出会有差异,多次运行以后出现了两种结果[JavaScript] 纯文本查看 复制代码
console.log('1')
setTimeout(() => {
console.log('2')
})
new Promise((resolve, rejects) => {
console.log('3')
resolve()
}).then(() => {
let i = 0
while(i < 1000000000) {
i++
}
console.log('4')
})
let i = 0
while(i < 1000000000) {
i++
}
console.log(5)