我可以“跨越”吗?只是jQuery代码,而调试? [英] Can I "step over" just jQuery code while debugging?

查看:139
本文介绍了我可以“跨越”吗?只是jQuery代码,而调试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用jQuery的脚本中,我 想要测试我写的代码。我不想进入jQuery文件 - 我没有调试jQuery,只是我自己的文件。

有什么方法可以告诉调试器不步入jQuery文件?我使用Visual Studio + Internet Explorer,以及Firefox + Firebug来实现代码...这两种方式似乎都喜欢通过几十个jQuery语句。



例如,假设我有这样一个脚本:

$ $ $ $ $ $ $ $ $ $ $ $ $(div)each(function(){
$(this).hide();
});

这在技术上是一个单独的语句 - 因此Step Over将立即执行所有的代码,将跳过内部的隐藏声明。然而,Step Into将把我带到jQuery代码中,在将我带到hide语句之前,我必须执行几十行代码。



我想让调试器完全忽略jQuery代码,所以我可以很容易地通过我自己的代码,并从不通过jQuery代码。



在C#中,这可以通过在类上使用[DebuggerStepThrough()]属性来实现。但是这对JavaScript没有帮助。

解决方案

是的,您可以



<至少在FireFox(25+)和Chrome(30 +)中。

在FireFox中这个特性被称为Black boxing code>,并且可以与FireFox 25一起使用。它让我们做你正在寻找的东西:

b
$ b

Chrome(v30 +)还引入了此功能,但查找/配置比较困难。它被称为跳过特定名称的源代码,Collin Miller在描述如何配置它方面做得非常出色:

/ a>



我现在在Chrome中使用它。它像一个魅力,并节省了我这么多的时间。


While stepping through a script that uses jQuery, I just want to test the code I wrote. I don't want to step into the jQuery file -- I'm not debugging jQuery, just my own file.

Are there any ways to tell a debugger to not step into the jQuery file? I use Visual Studio + Internet Explorer, as well as Firefox + Firebug for stepping through code ... and both seem to love to step through dozens of jQuery statements.

For example, say I have a script like this:

$("div").each(function() {
   $(this).hide();
});

This is technically a single statement -- therefore "Step Over" will execute all code at once, which will skip over the inner "hide" statement. However, "Step Into" will take me to the jQuery code, and I will have to step dozens of lines of code before it takes me to the "hide" statement.

I would like to have the debugger completely ignore the jQuery code, so I can easily step through just my own code and never step through the jQuery code.

In C#, this is possible by using the [DebuggerStepThrough()] attribute on a class. But that doesn't help with JavaScript.

解决方案

Yes you can

At least in FireFox (25+) and Chrome (30+).

In FireFox this feature is called "Black boxing" and will be available with FireFox 25. It let's do exactly what you where looking for:

Nick Fitzgerald and Chris Heilmann: "New Features of Firefox Developer Tools: Episode 25"

This feature was also introduced to Chrome (v30+) although it's tougher to find/configure. It's called "skip through sources with particular names" and Collin Miller did an excellent job in describing how to configure it:

Collin Miller: "Tips and Tricks: Ignoring library code while debugging in Chrome"

I'm using it in Chrome right now. It works like a charm and saves me so much time.

这篇关于我可以“跨越”吗?只是jQuery代码,而调试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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