27
May

Love / Hate of console.log

   Posted by: admin   in Uncategorized

console.log is the most necessary debug tool for javascript ever, but it only works in FireFox with FireBug. Otherwise it gives you an error, could sabotage all of your other javascript. You could just comment them all out before releasing code. OR you can add a condition around it so that it only shows if it won’t error.

For security reasons you may want to comment out the console.logs anyways, but it doesnt hurt to apply this method to make sure it never produces an error.

if(typeof console.log == ‘function’){ console.log(‘your log string or object here’); }

Share and Enjoy:
  • Digg
  • Technorati
  • Google Bookmarks
  • del.icio.us
  • Facebook
  • StumbleUpon

Tags:

This entry was posted on Wednesday, May 27th, 2009 at 8:44 am and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One comment

Tim
 1 

An easier solution, would be to just add:

if (!(‘console’ in window)) window['console'] = { log : function(){}};

This way you can call console.log without fear of retribution.

August 13th, 2009 at 2:21 pm

Leave a reply

Name (*)
Mail (will not be published) (*)
URI
Comment