Forked from nicjansma/ie89-console-apply-support.js
Last active
August 29, 2015 14:05
-
-
Save krusynth/7ad5d1d1e8420a66c13a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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