一道題判斷本身是否明白node事件機制

const fs = require('fs');
(function mainline() {
    Promise.resolve().then(res => { console.log('D') });

    process.nextTick(res => { console.log('C') });

    console.log('A');

    setTimeout(() => {
      console.log('N')
      process.nextTick(() => { console.log('O') })
    },0); // delay 爲 80 的時候答案時多少呢?

    setImmediate(() => {
        console.log('G');
        fs.readFile('./vuex.mp4', 'utf8', (err, files) => { console.log('J') })
    });
    
    fs.readFile('./vuex.mp4', 'utf8', (err, files) => {
        console.log('E');

        setTimeout(() => { console.log('M') }, 50);

        setTimeout(() => { console.log('L') },20);

        setImmediate(() => { console.log('H') });

        process.nextTick(() => {
            console.log('F');

            setImmediate(() => {
              console.log('I');

              setImmediate(() => {
                  console.log('K');
              });
            });

            setTimeout(() => { console.log('我在哪裏') }, 0);
        });
        console.log('我又在哪裏')
    });
    console.log('B');
})();
複製代碼

答案是什麼呢?vue

若是你能在不運行代碼的狀況下說出答案,那麼,恭喜你戰勝了99%的node工程師。node

相關文章
相關標籤/搜索