简体   繁体   English

是否有可能铬调试iife javascript?

[英]is it possible to chrome debug iife javascript?

I've been running into this issue a lot recently. 我最近一直在讨论这个问题。 I go the source panel in chrome dev tools in order to debug some javascript. 我在chrome dev工具中使用源代码面板来调试一些javascript。 In the past I've clicked onto a line where I want the debugger to stop. 在过去,我点击了一行,我希望调试器停止。 The line number turns blue, then when I trigger the function call, the program stops and I can look at variables. 行号变为蓝色,然后当我触发函数调用时,程序停止,我可以查看变量。

Recently I've run into a situation a couple time where I try to click into a function, but the display indicated I'm not setting a breakpoint. 最近我遇到了一个情况,我尝试点击一个函数,但显示屏显示我没有设置断点。 The thing that's common between both time is that I'm working with Immediately Invoked Function Expressions(IIFE). 两者之间的共同点是我正在使用Immediately Invoked Function Expressions(IIFE)。 Is it possible to set breakpoints in a iife without access to the source code? 是否可以在不访问源代码的情况下在iife中设置断点?

You mentioned being able to set a breakpoint in an IIFE without access to the source code, so I setup two examples that you can try where you do not have access to source assuming you meant local disk. 您提到能够在IIFE中设置断点而无法访问源代码,因此我设置了两个示例,您可以尝试在无法访问源的位置,假设您的意思是本地磁盘。 In either example, I was able to set a break point on any of the relevant IIFE lines and step into/over as expected using Chrome. 在任何一个例子中,我都可以在任何相关的IIFE线上设置断点,并使用Chrome按预期进入/超过。

BTW - In neither example did I experience the behavior where Chrome did not set the breakpoint as expected. 顺便说一句 - 在这两个例子中,我都没有遇到Chrome未按预期设置断点的行为。

JSFiddle: https://jsfiddle.net/iamwaltuo/fu1pcwqf/ JSFiddle: https ://jsfiddle.net/iamwaltuo/fu1pcwqf/

Dropbox: https://www.dropbox.com/s/khlmi6c2fezv0tn/iifetest.html?raw=1 Dropbox: https ://www.dropbox.com/s/khlmi6c2fezv0tn/iifetest.html raw = 1

<html>
    <head>
        <script type="text/javascript">
            (function () {
                var i = 0;
                console.log("i = " + i++);
                console.log("i = " + i++);
            })();
        </script>       
    </head>
    <body>
        Check the console
    </body>
</html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM