没有ID的clearTimeout [英] clearTimeout without ID

查看:40
本文介绍了没有ID的clearTimeout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果没有明确的ID,有什么方法可以清除 setTimeout()?问题是我不允许更改一些已经运行的代码,并在没有任何处理程序的情况下设置计时器.

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 timers without any handler.

JS是否为它们设置了匿名处理程序"?这些计时器是否存储在任何可访问的位置?我可以获取这些属性中的任何一个吗(计时器将要调用的功能?将被调用的时间?)

Does JS set 'anonymous handlers' to them? Are these timers stored anywhere accessible? Can I get any of those properties (the function the timer is about to call? the time it'll be called?)

推荐答案

不,您不能没有参考.您可以尝试尝试真正 hacky(不要这样做!这只是hackyness的例证),以清除所有超时:

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);

但这又不是万无一失的,而且远远超出了hacky.

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

解决方案?Fight可以更改信号源,因此您可以正确执行此操作-或查看是否可以覆盖创建计时器的功能.

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.

这篇关于没有ID的clearTimeout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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