Skip to content

Instantly share code, notes, and snippets.

@hackingbeauty
Created October 18, 2012 01:30
Show Gist options
  • Save hackingbeauty/3909370 to your computer and use it in GitHub Desktop.
Save hackingbeauty/3909370 to your computer and use it in GitHub Desktop.
Avoiding console.log errors
// Avoid `console` errors in browsers that lack a console.
(function() {
var noop = function noop() {};
var methods = [
'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
'timeStamp', 'trace', 'warn'
];
var length = methods.length;
var console = window.console || {};
while (length--) {
// Only stub undefined methods.
console[methods[length]] = console[methods[length]] || noop;
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment