Reputation: 19831
I'm using firebug and making lots of console.log, .info, .dir calls, etc. When the app runs on a machine with firebug turned off, it can cause errors. What's the best technique to avoid that? This seems to work:
// global scope
if (typeof(console) == 'undefined') {
console = {
info : function() {},
dir : function() {},
error : function() {},
log : function() {}
};
}
but I don't like the idea of manually maintaining a list of console functions. Other ideas?
(We've also got jQuery on the project if that helps.)
Upvotes: 4
Views: 1146
Reputation: 630569
I personally just use $.noop
to shorten it like this:
if(!window.console)
window.console = { log: $.noop, group: $.noop, groupEnd: $.noop };
But whatever functions you're using, add them in.
Upvotes: 3