• <legend id='IvASe'><style id='IvASe'><dir id='IvASe'><q id='IvASe'></q></dir></style></legend>
    1. <i id='IvASe'><tr id='IvASe'><dt id='IvASe'><q id='IvASe'><span id='IvASe'><b id='IvASe'><form id='IvASe'><ins id='IvASe'></ins><ul id='IvASe'></ul><sub id='IvASe'></sub></form><legend id='IvASe'></legend><bdo id='IvASe'><pre id='IvASe'><center id='IvASe'></center></pre></bdo></b><th id='IvASe'></th></span></q></dt></tr></i><div id='IvASe'><tfoot id='IvASe'></tfoot><dl id='IvASe'><fieldset id='IvASe'></fieldset></dl></div>
      <tfoot id='IvASe'></tfoot>

        • <bdo id='IvASe'></bdo><ul id='IvASe'></ul>

        <small id='IvASe'></small><noframes id='IvASe'>

        使用 javascript 确定 javascript 中的堆栈深度

        时间:2023-10-20

          <tbody id='IX2zx'></tbody>
        <tfoot id='IX2zx'></tfoot>

        <i id='IX2zx'><tr id='IX2zx'><dt id='IX2zx'><q id='IX2zx'><span id='IX2zx'><b id='IX2zx'><form id='IX2zx'><ins id='IX2zx'></ins><ul id='IX2zx'></ul><sub id='IX2zx'></sub></form><legend id='IX2zx'></legend><bdo id='IX2zx'><pre id='IX2zx'><center id='IX2zx'></center></pre></bdo></b><th id='IX2zx'></th></span></q></dt></tr></i><div id='IX2zx'><tfoot id='IX2zx'></tfoot><dl id='IX2zx'><fieldset id='IX2zx'></fieldset></dl></div>
        1. <legend id='IX2zx'><style id='IX2zx'><dir id='IX2zx'><q id='IX2zx'></q></dir></style></legend>

          • <small id='IX2zx'></small><noframes id='IX2zx'>

                <bdo id='IX2zx'></bdo><ul id='IX2zx'></ul>
                • 本文介绍了使用 javascript 确定 javascript 中的堆栈深度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有没有办法通过使用 javascript 本身来确定在 javascript 中执行的所有函数的堆栈深度?

                  Is there a way to determine the stack depth of all functions being executed in javascript by using javascript itself?

                  我在想这可能涉及修改 Function 原型,但我真的不知道.

                  I'm thinking it might involve modifying the Function prototype, but I really don't have any idea.

                  此外,能够在堆栈深度足够高的任何时候中断会很好.

                  Additionally, it would be nice to be able to break anytime the stack depth were sufficiently high.

                  原因是我有一个 IE 中的堆栈溢出错误,显然不可调试.我很懒惰,我宁愿不必通过我维护的代码来寻找原因.

                  The reason for this is that I have a stack overflow error in IE which is apparently not debuggable. I'm lazy and I would rather not have to hunt through the code that I'm maintaining to find the cause.

                  感谢您帮助我的懒惰.

                  推荐答案

                  ECMAscript 支持 Function.prototype.caller 属性已经有一段时间了.即使它在 ES5 strict 中被弃用,IE 仍然应该支持它.因此,您基本上可以通过所涉及的功能循环往上.

                  ECMAscript supported for quite a while the Function.prototype.caller property. Even if its deprecated in ES5 strict, IE should still support it. So you could basically loop your way up through the involved functions.

                  function one() {
                     two();
                  }
                  
                  function two() {
                     three();
                  }
                  
                  function three() {
                      var caller = three.caller;
                  
                      console.log('caller was: ', caller.name);
                  
                      while( caller = caller.caller ) {
                             console.log('caller was: ', caller.name);
                      }
                  }
                  
                  (function outer() {
                      one();
                  }());
                  

                  这将输出:

                  caller was: two
                  caller was: one
                  caller was: _outer
                  

                  因此,如果您知道错误发生在哪个函数中,那么您就可以从最初调用该方法的方式中得到答案.如果您只是在深度之后,您可以计算对 caller.caller 属性进行了多少次交互.至少 IE8 应该支持debugger"语句,您可以在该脚本中调用它来将调试器带到舞台上.

                  So, if you know in which function an error happens, that way you get the answer all the way up how this method was originally called. If you're just after the depth, you can just count how many interations over the caller.caller property were made. At least IE8 should support the "debugger" statement, which you could just call in that script to bring the debugger on the stage.

                  这篇关于使用 javascript 确定 javascript 中的堆栈深度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:jQuery 推送堆栈 下一篇:只有 HTML/JS 和谷歌地图上的实时 GPS 追踪器可以在手机上运行?是否可以?

                  相关文章

                    <small id='Xtx0J'></small><noframes id='Xtx0J'>

                  1. <i id='Xtx0J'><tr id='Xtx0J'><dt id='Xtx0J'><q id='Xtx0J'><span id='Xtx0J'><b id='Xtx0J'><form id='Xtx0J'><ins id='Xtx0J'></ins><ul id='Xtx0J'></ul><sub id='Xtx0J'></sub></form><legend id='Xtx0J'></legend><bdo id='Xtx0J'><pre id='Xtx0J'><center id='Xtx0J'></center></pre></bdo></b><th id='Xtx0J'></th></span></q></dt></tr></i><div id='Xtx0J'><tfoot id='Xtx0J'></tfoot><dl id='Xtx0J'><fieldset id='Xtx0J'></fieldset></dl></div>

                  2. <tfoot id='Xtx0J'></tfoot>
                    <legend id='Xtx0J'><style id='Xtx0J'><dir id='Xtx0J'><q id='Xtx0J'></q></dir></style></legend>

                      • <bdo id='Xtx0J'></bdo><ul id='Xtx0J'></ul>