Posts Tagged ‘debugging’
Firebug “console is undefined”
If you’re using Firebug and don’t want to bother removing or commenting out all the console.log debug messages for users who aren’t, put this at the top:
if(typeof(console) === "undefined" || typeof(console.log) === "undefined") var console = { log: function() { } };
This reminds me of the trick I use for C/C++ of putting debugging statements inside a macro:
D(cerr<<"The number is "<<n<<endl;);
where the macro D is defined as
#define D(A) A
when you want the debugging code to run, and
#define D(A)
when you don’t. :-)
(The final semicolon after the D() is for Emacs to indent it reasonably.)
Update: Of course, the above are just hacky hacks to save typing. The “right” way for conditional C code is usually to use #ifdef DEBUG and the like, and the right way around the Firebug problem is to use something more general like this code at metamalcolm.