clearTimeout without ID

后端 未结 4 1104
日久生厌
日久生厌 2021-01-14 02:16

Is there any way to clear setTimeout() if it doesn\'t have an explicit ID? The problem is I\'m not allowed to change some code that already ran and set the tim

4条回答
  •  长情又很酷
    2021-01-14 02:45

    Nope, you can't without a reference. You could try something REALLY hacky (don't do this! it's just an illustration of hackyness) to clear all timeouts:

    for(var i=0; i<100000; i++) clearTimeout(i);
    

    but again that's not foolproof and well beyond hacky.

    Solution? Fight be able to change the source, so you can do this properly - or see if you can override the function creating the timer.

提交回复
热议问题