February 2010 (1)
September 2009 (1)
May 2009 (1)
April 2009 (1)
March 2009 (4)
January 2009 (3)
November 2008 (2)
October 2008 (2)
September 2008 (1)
August 2008 (5)
July 2008 (3)
June 2008 (1)
May 2008 (5)
April 2008 (8)
March 2008 (3)
February 2008 (1)
January 2008 (2)
December 2007 (2)
November 2007 (4)
October 2007 (17)
September 2007 (9)
2010-02-04 17:46:38
I love Firebug, and I especially love sprinking console.log calls around the place, but I hate the way things break when you forget to remove them and your code hits a browser without Firebug installed.
if (typeof console === 'undefined') {
var console = {}; // For once not having block scoping is kind of handy
console.log = function () {};
};
console.log("It's safe to use console.log");
I feel there ought to be a smarter way of doing this but I just can’t think of one.
From PK on 2011-12-04 00:05:06
I call a function tryConsole which does the console.log after browser sniffing. Same ends I guess.
Rendered at 2012-02-10 00:22:59
From Danielnashnz on 2011-01-24 12:26:15
If ‘window.console’ and ‘window.firebug’ are not defined, stub an object with an empty .log() and .warn() method, and ref it as ‘var console’ in global scope.