检查是否已调用clearInterval? [英] Checking whether clearInterval has been called?

查看:148
本文介绍了检查是否已调用clearInterval?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于此代码:

bob = setInterval(function, 1000);
clearInterval(bob);

现在有办法知道该间隔是否已被清除?

Is there now a way to know if that interval has been cleared?

目前,我通过取消设置' bob '来跟踪这个问题,但我很好奇我是否需要额外的代码行:

Currently, I keep track of this myself, by unsetting 'bob', but I'm curious if my extra line of code is unnecessary:

clearInterval(bob);
bob = null;
if (!bob) itIsCleared();

谢谢!

推荐答案

setInterval 的返回值只是用于传递回 clearInterval <的唯一ID / code>。它不是具有任何附加信息的结构化对象,当您调用 clearTimeout 时也不会设置为null。

The return value of setInterval is just a unique id you use to pass back to clearInterval. It's not a structured object with any additional information, nor does it get set to null when you call clearTimeout.

这篇关于检查是否已调用clearInterval?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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