Skip to content

Instantly share code, notes, and snippets.

@Jpunt
Last active January 2, 2016 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Jpunt/8334615 to your computer and use it in GitHub Desktop.
Save Jpunt/8334615 to your computer and use it in GitHub Desktop.
Fallback to use things like console.log() but not have it kill old browsers.
// This is not some kind of polyfill! It's just to prevent old browsers from failing horribly
var fallback = function() {};
var methods = ['assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log', 'profile', 'profileEnd', 'time', 'timeEnd', 'timeStamp', 'trace', 'warn', 'table'];
if(typeof console === 'undefined') {
var console = {};
}
for(var i in methods) {
if(typeof console[methods[i]] === 'undefined') {
console[methods[i]] = fallback;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment