Skip to content

Commit

Permalink
Ensure IE check works in IE < 9
Browse files Browse the repository at this point in the history
Ok, strictly speaking this isn't too important, as it's been
a long time since IE9 came out, but that's what we say we
support, it's easy enough to support it here, and one of the
big reasons this library exists is to give you reliable
logging, everywhere. It's nice to do that *everywhere*, when
we can.
  • Loading branch information
pimterry committed Nov 7, 2019
1 parent 81bccb5 commit fdd97e5
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/loglevel.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
var noop = function() {};
var undefinedType = "undefined";
var isIE = (typeof window !== undefinedType) && (
window.navigator.userAgent.indexOf('Trident/') >= 0 ||
window.navigator.userAgent.indexOf('MSIE ') >= 0
/Trident\/|MSIE /.test(window.navigator.userAgent)
);

var logMethods = [
Expand Down Expand Up @@ -51,7 +50,14 @@

// Trace() doesn't print the message in IE, so for that case we need to wrap it
function traceForIE() {
if (console.log) console.log.apply(console, arguments);
if (console.log) {
if (console.log.apply) {
console.log.apply(console, arguments);
} else {
// In old IE, native console methods themselves don't have apply().
Function.prototype.apply.apply(console.log, [console, arguments]);
}
}
if (console.trace) console.trace();
}

Expand Down

0 comments on commit fdd97e5

Please sign in to comment.