Have you ever added a couple of console.log calls to your javascript, test it in Firefox, then go into Internet Explorer and see tons of mysterious errors popup? I sure have, I always forget about those console.logs that are interwoven in my code. While it isn’t hard to do a replace on them all, I usually want to keep them where they are.
I recently came up with a solution to this problem, different from the one I wrote about before. I wrote a little function called log. As you can see, it is the simplest thing in the world.
function log(arg) { console.log(arg); }
So what’s the big deal? Let me explain. If you’re testing in Firefox with Firebug, you won’t notice much difference. But if you need to test in Internet Explorer now, you can just comment one line, that internal console.log which is faster and easier than commenting out all of them by hand.
Or there’s always http://mootools.net/docs/more/Core/Log, or, which I prefer, my own home-brewed logging system. Basically, instead of “console.log” or “console.info” or whatever, you have “dbug.log”, and then if (window.console) is truthy (and you’ve enabled it), it’ll push it out to the console.
More/Log wasn’t around when I originally wrote this post a couple weeks ago, but since then and looking at Log, it is nice.