Skip to content

Instantly share code, notes, and snippets.

@nicjansma
Created January 29, 2013 17:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nicjansma/4666076 to your computer and use it in GitHub Desktop.
Save nicjansma/4666076 to your computer and use it in GitHub Desktop.
Adds .apply() and .call() support to IE8/9's console object, which treates .log()/etc as Objects and not Functions. Requires jQuery for $.each().
if (Function.prototype.bind && typeof console == "object" && typeof console.log == "object") {
var logFns = ["log", "info", "warn", "error", "assert", "dir", "clear", "profile", "profileEnd"];
$.each(logFns, function (i, method) {
console[method] = Function.prototype.call.bind(console[method], console);
});
}
@meszaros-lajos-gyorgy
Copy link

Requiring jquery just to iterate through the logFns array seems a bit overkill for projects, which do not use jquery. You could use: for (var i = 0; i < logFns.length; i++) { on line #4 and add an extra line after it: var method = logFns[i];.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment