Skip to content

Instantly share code, notes, and snippets.

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 krusynth/7ad5d1d1e8420a66c13a to your computer and use it in GitHub Desktop.
Save krusynth/7ad5d1d1e8420a66c13a to your computer and use it in GitHub Desktop.
/*
* Patch to make console.log, console.warn, etc work in IE8 & 9
*/
// Default list of functions for console.
var logFns = ["log", "info", "warn", "error", "assert", "dir", "clear", "profile", "profileEnd"];
// Define console.
if (typeof console == 'undefined') {
console = {};
}
// Define all of our methods that are missing.
// They will do nothing, but that's better than throwing an error.
for(var i in logFns) {
var method = logFns[i];
if(typeof console[method] == 'undefined') {
console[method] = function () {};
}
}
/*
* Wrap any methods that exist into objects. Allows .apply() binding later.
* Based on https://gist.github.com/nicjansma/4666076
*/
if (Function.prototype.bind && typeof console == "object" && typeof console.log == "object") {
for(var i in logFns) {
var method = logFns[i];
console[method] = Function.prototype.call.bind(console[method], console);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment