-
Code Snippet to Log All Events as They Are Triggered - [Javascript]
2009-04-28
I paired with Josh Price wrote the javascript code below, just before that we noticed something abnormal about event handling and wanted to find out what happened.
Just paste the code below into Firebug console of Firefox, run it, do something triggering events in page and watch the log printed out.
Please note that this requires jQuery.
var counter = 0; $("*").each(function() { var events = $(this).data('events'); if(events) { $.each(events, function(type, handlers) { $.each(handlers, function(i, handler){ handlers[i] = function(){ handler.apply(this, arguments); console.log(++counter, type); }; }); }); } });
You can add more logging per your need, e.g. the time used for each handler call.
收藏到:Del.icio.us
<< A Quick Check of Javascript Code Quality | Home | Remove the Noisy Thread.Sleep and WaitForCondition from Selenium Tests >>