Debugging JavaScript events with Firebug

后端 未结 8 1051
情话喂你
情话喂你 2020-12-24 02:31

I need to set a breakpoint to certain event, but I don\'t know, where is it defined, because I\'ve got giant bunch of minimized JavaScript code, so I can\'t find it manually

相关标签:
8条回答
  • 2020-12-24 03:26

    Well it might all be too much trouble than it's worth, but it looks like you have three things to do:

    1. De-minify the source. I like this online tool for a quick and dirty. Just paste your code and click the button. Has never let me down, even on the most funky of JavaScript.

    2. All jQuery event binders get routed to "jQuery.event.add" (here's what it looks like in the unbuilt source), so you need to find that method and set a breakpoint there.

    3. If you have reached this far, all you need to do is inspect the callstack at the breakpoint to see who called what. Note that since you're at an internal spot in the library you will need to check a few jumps out (since the code calling "jQuery.event.add" was most likely just other jQuery functions).

    Note that 3) requires Firebug for FF3. If you are like me and prefer to debug with Firebug for FF2, you can use the age-old arguments.callee.caller.toString() method for inspecting the callstack, inserting as many ".caller"s as needed.


    Edit: Also, see "How to debug Javascript/jQuery event bindings with FireBug (or similar tool)".

    You may be able to get away with:

    // inspect    
    var clickEvents = jQuery.data($('#foo').get(0), "events").click;
    jQuery.each(clickEvents, function(key, value) {
        alert(value) // alerts function body
    })
    

    The above trick will let you see your event handling code, and you can just start hunting it down in your source, as opposed to trying to set breakpoint in jQuery's source.

    0 讨论(0)
  • 2020-12-24 03:26

    First replace minified jquery or any other source you use with formated. Another useful trick I found is using profiler in firebug. The profiler shows which functions are being executed and you can click on one and go there to set a breakpoint.

    0 讨论(0)
提交回复
热议问题