使用setTimeout时你需要clearTimeout吗? [英] When using setTimeout do you have to clearTimeout?

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

问题描述

有人告诉我,当你使用 setTimeout 时,必须用 clearTimeout 清除它。我可以在超时用完之前理解,但为什么之后呢?或者它是不真实的?

Someone told me that when you use setTimeout you must clear it with clearTimeout. I can understand before the timeout runs out, but why after? Or is it untrue?

推荐答案

这不是真的 - 在完成后清除超时没有坏处,但它没有必要。

It's not true - there's no harm in clearing a timeout after it has finished, but it's not necessary.

根据规范


如果句柄未识别出活动计时器列表中的条目调用[clearTimeout]的WindowOrWorkerGlobalScope对象,该方法什么都不做。

If handle does not identify an entry in the list of active timers of the WindowOrWorkerGlobalScope object on which [clearTimeout] was invoked, the method does nothing.

换句话说,它是一个无操作;没有任何反应,也不会抛出任何错误。

In other words, it's a no-op; nothing happens, and no error will be thrown.

这篇关于使用setTimeout时你需要clearTimeout吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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