Skip to content

Instantly share code, notes, and snippets.

@michalbcz
Last active December 21, 2015 01:39
Show Gist options
  • Select an option

  • Save michalbcz/6229572 to your computer and use it in GitHub Desktop.

Select an option

Save michalbcz/6229572 to your computer and use it in GitHub Desktop.
emulating window.console to prevent undefined errors for older browser (like IE7/8) which have no native console object or haven't got appropriate log methods
/*
* Initialize console object used for logging in javascript code.
* For case when console object is not present (old browsers) use dump implementation.
*/
window.console = window.console || {}; // in old browsers like IE7 there is no console object
console.info = console.info || function() {};
console.error = console.error || function() {};
console.warn = console.warn || function() {};
console.debug = console.debug || console.info; // in later IE there is console but without debug method, so fallback to info
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment