为什么setTimeout()在Chrome DevTools下混乱我的调用堆栈? [英] Why does setTimeout() clutter my call stack under Chrome DevTools?

查看:420
本文介绍了为什么setTimeout()在Chrome DevTools下混乱我的调用堆栈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数,在完成后使用setTimeout()重新排队。有人可以解释为什么Chrome DevTools会让它看起来像是在递归地调用它自己吗?我的理解是调用堆栈应该在每次调用时都清楚。

I have a function that upon completion re-queues itself with setTimeout(). Could someone explain why Chrome DevTools makes it look like it's calling itself recursively? My understanding is the call stack ought to be clear on each invocation.

举一个非常简单的例子:

Take this very simple example:

<html>
  <head>
    <script>
      function main() {
        setTimeout(main, 100);  // set breakpoint here
      }
      main();
    </script>
  </head>
  <body></body>
</html>

第一次遇到断点我看到了:

The first time the breakpoint is hit I see this:

经过3次迭代后我看到了:

After 3 more iterations I see this:

Firefox开发人员工具可以达到我的预期,并且只显示堆栈上的一个函数实例每次断点都被击中。

Firefox developer tools does what I expect and just shows one instance of the function on the stack each time the breakpoint is hit.

是在Chrome下我有一些微妙的参考捕获,我不知道,或者这只是一个DevTools UI的东西?

Is there some kind of subtle reference capture going on under Chrome that I'm not aware of, or is this just a DevTools UI thing?

推荐答案

要隐藏它 - 转到

Devtools设置 - >首选项 - >调试器

选中禁用异步堆栈跟踪


但我强烈建议离开就是这样。它对调试非常有用。

To hide it - go to
Devtools Settings -> Preferences -> Debugger
Check "Disable async stack traces"
But I strongly recommend to leave it as is. It is very useful for debugging.

这篇关于为什么setTimeout()在Chrome DevTools下混乱我的调用堆栈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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