JavaScript中的setTimeout()是同步的还是异步的?

时间:2018-08-17 08:31:36

标签: javascript synchronization settimeout

我有以下利用setTimeout()函数的函数

someElement.addEventListener('click', function () {
    someElement.classList.remove('active');
    someElement.classList.remove('active--show');
    setTimeout(function () {
        someElement.classList.remove('some--class')
    }, 3000);
    someElement.classList.remove('another--class');
    someElement.classList.remove('and--another--class');
    someElement.classList.remove('and--another--class--again');
});

当到达setTimeout()函数时,当前函数是否继续运行以下命令(下面的代码段)?一旦经过3秒钟,就运行setTimeout()内部的脚本功能?

someElement.classList.remove('another--class');
someElement.classList.remove('and--another--class');
someElement.classList.remove('and--another--class--again');

还是进入setTimeout()函数,等待3秒钟,然后在其中运行脚本,然后继续执行原始功能的其余部分?

对此有任何建议。

谢谢

0 个答案:

没有答案