Thomas Fuchs
Hi, I'm Thomas Fuchs. I'm the author of Zepto.js, of, and I'm a Ruby on Rails core alumnus. With Amy Hoy I'm building cheerful software, like Noko Time Tracking and Every Time Zone and write books like
   Want me to speak at your conference? Contact me!

Little JavaScript hints, episode 1: prevent console.log breakage

December 19th, 2008

Here’s something I’ve tripped over in the past, and it hit me again while developing some JavaScript for freckle.

Firebug’s console.log is of great value. But don’t dare you forget it in your code before you deploy…

Here’s a quick snippet that saves your code from exploding (this is for peeps that use Prototype):

if(window['console'] === undefined)
  window.console = { log: Prototype.emptyFunction };

This should prevent the worst, but of course always check your code when you deploy. D’oh!