diff --git a/lib/loglevel.js b/lib/loglevel.js index 514ed50..e599208 100644 --- a/lib/loglevel.js +++ b/lib/loglevel.js @@ -7,7 +7,7 @@ ;(function (undefined) { var undefinedType = "undefined"; - + (function (name, definition) { if (typeof module !== 'undefined') { module.exports = definition(); @@ -38,17 +38,26 @@ var method = console[methodName]; if (method.bind === undefined) { if (Function.prototype.bind === undefined) { - return function() { - Function.prototype.apply.apply(method, [console, arguments]); - }; + return functionBindingWrapper(method, console); } else { - return Function.prototype.bind.call(console[methodName], console); + try { + return Function.prototype.bind.call(console[methodName], console); + } catch (e) { + // In IE8 + Modernizr, the bind shim will reject the above, so we fall back to wrapping + return functionBindingWrapper(method, console); + } } } else { return console[methodName].bind(console); } } + function functionBindingWrapper(f, context) { + return function() { + Function.prototype.apply.apply(f, [context, arguments]); + }; + } + var logMethods = [ "trace", "debug",