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

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

问题描述

我在我的应用程序中使用了 setTimeout() 函数,但是什么时候进行垃圾收集.该方法仍然运行并调用一个函数.如何阻止它调用某个函数.我尝试将其设置为 null 但它不起作用

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天全站免登陆