gpt4 book ai didi

javascript - 使用 setTimeout 时是否必须清除超时?

转载 作者:IT王子 更新时间:2023-10-29 02:54:05 27 4
gpt4 key购买 nike

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

最佳答案

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

根据 specification :

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.

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

关于javascript - 使用 setTimeout 时是否必须清除超时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7391567/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com