Debugging JavaScript

One of the things I hate about web development is the absolute pain in the ass that is JavaScript. It's not a terribly bad language in itself, with a decent anonymous function syntax and prototype-based object system (even if it's completely useless because there is no object database). But the fact that errors often pass silently and the debugging tools available are tedious and a pain to use makes developing with JS almost unbearable. I have often wished for the staple, the crutch of development in tool-poor environments, of the 'print' statement.

Here is how to configure Mozilla so that calls to 'dump()' will show up in the console:

Fire up Mozilla and type 'about:config' in the url bar.

Right click and choose 'New->Boolean'

Type 'browser.dom.window.dump.enabled'

Type 'true'

Start Mozilla from a shell, and you will finally be able to debug complex javascripts by printing things to the console using the 'dump' function.

By the way, to start Mozilla from the Terminal on Mac OS X, execute the binary:


1 comment:

Ian Bicking said...

What, window.alert() isn't good enough for you? OK-OK-OK-OK-OK-OK-OK-OK-OK-OK... there's the bug! wait, no, that's right... OK-OK-OK-OK-OK-OK-OK-...