Does the browser keep track of active timer IDs?

后端 未结 5 1262
没有蜡笔的小新
没有蜡笔的小新 2021-02-05 09:34

Does the browser keep track of active setInterval and setTimeout IDs? Or is this solely up to the developer to keep track of?

If it does keep t

5条回答
  •  说谎
    说谎 (楼主)
    2021-02-05 10:07

    It is up for the developer to keep track of. You can do so by using the returned value of the setTimeout/setInterval function and passing that value to the clearTimeout/clearInterval function - as described in other answers here.

    This appears to be because each browser will implement keeping track of the intervals in their own way.

    From w3.org/TR/2009/WD-html5-20090212/no.html (a draft, but w3schools and http://w3.org/TR/Window explain it almost the same way) - setTimeout and setInterval return a long and clearTimeout/clearInterval accept a long to find and cancel

提交回复
热议问题