Nothing Insightful

  • Archive
  • RSS

Developer Snippet - Capturing Console.Log

Nobody is perfect. I’ve left a console.log() in countless live deployments, and I will probably do it again. While it does speak volumes about my attention to detail after a long day of coding, there is a way to prevent it. It’s easy enough to detect when the console object doesn’t exist - so you can just do the following.

if (!window.console) {

window.console = {};

window.console.log = function() {

return false;

};

}

The only thing is that, well, I’m not particularly fond of this snippet. While it’s a good development tool for quick and easy testing in Internet Explorer and other browsers that do not support console logging, I don’t recommend you push this live. Not only does it promote lazy coding habits and deployment protocols, but it also encourages developers to litter the end user’s console with statements. On the other hand it does lend itself to better bug tracking and support on a live site. This is best determined on a case-by-case situation.

I created a GitHub gist for better readability and comment tracking. I wish Tumblr would allow iframe embedding or at least code formatting.

    • #snippet
    • #tip
    • #handy hint
    • #javascript
    • #webdev
    • #front end dev
  • 9 months ago
  • 5
  • Comments
  • Permalink
  • Share

About

My name is Tait Brown, and I'm a Melbourne-based UI designer and a front end developer. I like to make stuff.

taitbrown@gmail.com

Me, Elsewhere

  • taitems on Dribbble
  • taitems on Forrst
  • @taitems on Twitter
  • taita_cakes on Last.fm
  • Linkedin Profile
  • taitems on github

Twitter

loading tweets…

  • RSS
  • Random
  • Archive
  • Mobile

Effector Theme by Carlo Franco.

Powered by Tumblr