Despite having worked on the very complex Firefox for a number of years, I’ll always love plain old console.log
debugging. Logging can provide an audit trail as events happen and text you can share with others. Did you know that chrome provides monitorEvents
and monitor
so that you can get a log each time an event occurs or function is called?
Monitor Events
Pass an element and a series of events to monitorEvents
to get a console log when the event happens:
// Monitor any clicks within the window monitorEvents(window, 'click') // Monitor for keyup and keydown events on the body monitorEvents(document.body, ['keyup', 'keydown'])
You can pass an array of events to listen for multiple events. The logged event
represents the same event you’d see if you manually called addEventListener
.
Monitor Function Calls
The monitor
method allows you to listen for calls on a specific function:
// Define a sample function function myFn() { } // Monitor it monitor(myFn) // Usage 1: Basic call myFn() // function myFn called // Usage 2: Arguments myFn(1) // function myFn called with arguments: 1
I really like that you can view the arguments provided, which is great for inspecting.
I usually opt for logpoints instead of embedding console
statements in code, but monitor
and monitorEvents
provide an alternative to both.
DWRequest: MooTools 1.2 AJAX Listener & Message Display
Though MooTools 1.2 is in its second beta stage, its basic syntax and theory changes have been hashed out. The JavaScript library continues to improve and become more flexible. Fellow DZone Zone Leader Boyan Kostadinov wrote a very useful article detailing how you can add a…
Form Element AJAX Spinner Attachment Using MooTools
Many times you’ll see a form dynamically change available values based on the value of a form field. For example, a “State” field will change based on which Country a user selects. What annoys me about these forms is that they’ll often do an…