如何杀死一个的setTimeout()函数函数、setTimeout

2023-09-09 21:24:19 作者:羽墨凌霄

我使用的setTimeout()函数,通过我的应用程序,但是当它的时间来收集垃圾。该方法仍然运行,并呼吁一个函数。如何从调用某个功能停止。我试着将它设置为空,但它不工作

I use the setTimeout() function through my application but when its time to garbage collect. the method still runs and calls on a function. How do I stop it from calling on a certain function. I tried setting it to null but it doesnt work

推荐答案

的setTimeout 返回引用超时,而当你调用 clearTimeout 就可以使用。

setTimeout returns an reference to the timeout, which you can then use when you call clearTimeout.

var myTimeout = setTimeout(...);
clearTimeout(myTimeout);
 
精彩推荐