diff --git a/src/logger/console.js b/src/logger/console.js index 681f6ab..93df1a1 100644 --- a/src/logger/console.js +++ b/src/logger/console.js @@ -6,11 +6,26 @@ define([ "compose", "../component/base" ], function ConsoleLogger(Compose, Component) { var CONSOLE = console; + // adapted from Mozilla Developer Network example at + // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind + var bind = Function.prototype.bind || function (obj) { + var args = slice.call(arguments, 1), + self = this, + nop = function () {}, + bound = function () { + return self.apply(this instanceof nop ? this : (obj || {}), args.concat(slice.call(arguments))); + }; + nop.prototype = this.prototype || {}; // Firefox cries sometimes if prototype is undefined + bound.prototype = new nop(); + return bound; + }; + return Compose.create(Component, { - "log" : CONSOLE.log.bind(CONSOLE), - "warn" : CONSOLE.warn.bind(CONSOLE), - "debug" : CONSOLE.debug.bind(CONSOLE), - "info" : CONSOLE.info.bind(CONSOLE), - "error" : CONSOLE.error.bind(CONSOLE) + "log" : bind.call(CONSOLE.log, CONSOLE), + "warn" : bind.call(CONSOLE.warn || CONSOLE.log, CONSOLE), + "debug" : bind.call(CONSOLE.debug || CONSOLE.log, CONSOLE), + "info" : bind.call(CONSOLE.info || CONSOLE.log, CONSOLE), + "error" : bind.call(CONSOLE.error || CONSOLE.log, CONSOLE) }); + }); \ No newline at end of file