再訪 event loop

總結

影片摘要:Further Adventures of the Event Loop

筆記 1

standard stack

microtask

(macro)task

影片演示(macro)task queue、animation callback queue 與 microtask

大約在 27:37 處開始:

題目解析:In The Loop

第一組程式碼:

const button = document.querySelector('button');

button.addEventListener('click', function first () {
  Promise.resolve().then(() => console.log('microtask 1'));
  console.log('listener 1');
});

button.addEventListener('click', function second() {
  Promise.resolve().then(() => console.log('microtask 2'));
  console.log('listener 2');
});

第二組程式碼:

const button = document.querySelector('button');

button.addEventListener('click', function first () {
  Promise.resolve().then(() => console.log('microtask 1'));
  console.log('listener 1');
})

button.addEventListener('click', function second() {
  Promise.resolve().then(() => console.log('microtask 2'));
  console.log('listener 2');
})

button.click();

影片摘要:Scheduling Tasks

筆記 2

參考文件