在javascript中查看所有超时/间隔? [英] Viewing all the timeouts/intervals in javascript?

查看:91
本文介绍了在javascript中查看所有超时/间隔?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个利用JavaScript超时和间隔来更新页面的应用程序。有没有办法看到设置了多少间隔?我想通过设置数百个间隔来确保我不会意外杀死浏览器。

I'm writing an application that utilizes JavaScript timeouts and intervals to update the page. Is there a way to see how many intervals are setup? I want to make sure that I'm not accidentally going to kill the browser by having hundreds of intervals setup.

这是一个问题吗?

推荐答案

我认为没有办法枚举活动计时器,但你可以覆盖window.setTimeout和window.clearTimeout并用你自己的替换它们执行一些跟踪然后调用原件的实现。

I don't think there is a way to enumerate active timers, but you could override window.setTimeout and window.clearTimeout and replace them with your own implementations which do some tracking and then call the originals.

window.originalSetTimeout=window.setTimeout;
window.originalClearTimeout=window.clearTimeout;
window.activeTimers=0;

window.setTimeout=function(func,delay)
{
    window.activeTimers++;
    return window.originalSetTimeout(func,delay);
};

window.clearTimeout=function(timerID)
{
    window.activeTimers--;
    window.originalClearTimeout(timerID);
};

当然,您可能并不总是调用clearTimeout,但这至少可以为您提供一些跟踪方法在运行时发生了什么。

Of course, you might not always call clearTimeout, but this would at least give you some way to track what is happening at runtime.

这篇关于在javascript中查看所有超时/间隔?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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