Skip to content

Instantly share code, notes, and snippets.

@0xadada
Created November 14, 2012 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xadada/4072758 to your computer and use it in GitHub Desktop.
Save 0xadada/4072758 to your computer and use it in GitHub Desktop.
javascript console logging protection
// Avoid 'console' errors in browsers that lack a console.
( function() {
var method;
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 = window.console || {} );
while ( length-- ) {
method = methods[length];
// Only stub undefined methods.
if ( !console[method] ) {
console[method] = noop;
}
}
}() );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment