Call setTimeout without delay

后端 未结 5 1025
闹比i
闹比i 2020-12-05 04:07

Quite often see in JavaScript libraries code like this:

setTimeout(function() {
    ...
}, 0);

I would like to know why use such a wrapper

5条回答
  •  遥遥无期
    2020-12-05 04:44

    There are a couple of reasons why you would do this

    • There is an action you don't want to run immediately but do want to run at some near future time period.
    • You want to allow other previously registered handlers from a setTimeout or setInterval to run

提交回复
热议问题