如何杀死一个的setTimeout()函数 [英] how to kill a setTimeout() function

查看:172
本文介绍了如何杀死一个的setTimeout()函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的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);

这篇关于如何杀死一个的setTimeout()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆