Created
July 6, 2013 07:45
-
-
Save jonsamwell/5939156 to your computer and use it in GitHub Desktop.
Added console support to older browsers (IE8 / 9)
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
(function (window, Function, $, YourNamespace) { | |
"use strict"; | |
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); | |
}); | |
} | |
YourNamespace.Logger = (function () { | |
var write = function (method, args) { | |
if (typeof window.console !== "undefined" && window.console[method] !== "undefined") { | |
console[method].call(window.console, args); | |
} | |
}, | |
log = function (msg) { | |
write('log', msg); | |
}, | |
error = function (msg, error) { | |
write('error', msg, error); | |
}; | |
return { | |
log: log, | |
error: error | |
}; | |
}()); | |
}(window, Function, $, YourNamespace)); | |
/* | |
Usage: YourNamespace.Logger.log('hello world'); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment