News for hackers. Stuff that matters.
Re:JavaScript Tips by bemmu on Thursday May 06, 2010 @04:47AM (#1323931)
Be very careful to not call console.log in any released code, or you'll have a very interesting time trying to figure out why your app works for exactly you and no-one else.
Re:JavaScript Tips by smanek on Thursday May 06, 2010 @05:36AM (#1324003)
I usually put a safety check at the top of my code, ensuring that console and console.log exist (and, if they don't, defining something appropriate in their place).
Re:JavaScript Tips by remi on Thursday May 06, 2010 @07:11AM (#1324115)

  if (!window.console) {
    window.console = {
      log:function(){},
      debug:function(){},
      trace:function(){}
    };
  }
Re:JavaScript Tips by DougWebb on Thursday May 06, 2010 @07:37AM (#1324145)
I just use:

    if ( errror ) {
        try { console.error(msg); }
        catch(e) {};
    }
Of course I do all of my debugging in Firefox with Firebug, and my goal is to ensure that these errors don't happen in production code so other browsers never hit the try/catch block. In rare cases where an error only happens in IE, I can throw an alert into the catch.
Re:JavaScript Tips by CoryMathews on Thursday May 06, 2010 @12:49PM (#1324834)
Its terrible practice to catch an error and do nothing with it.
Re:JavaScript Tips by DougWebb on Friday May 14, 2010 @04:54PM (#1348569)
Generally yes, I agree. But in this case all I'm doing with the error is displaying it to the programmer, and it doesn't matter to me if the programmer has to be using Firefox to see it. We were talking about displaying debugging messages and dealing with a missing console, not handling application failures.