Created
December 30, 2012 13:39
-
-
Save ofca-snippets/4412846 to your computer and use it in GitHub Desktop.
Safe, simple and cross browser (I hope) version of console.log
This file contains 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(root){ | |
if ( ! root['nano']) { root.nano = {}; } | |
/** | |
* Safe, simple and cross browser (I hope) version of console.log. | |
*/ | |
nano.console = (function(root) { | |
var csl = root.console || { log: function() {} }, | |
fn = function() { | |
var me = this, | |
l = ['log', 'warn', 'info', 'debug', 'error'], | |
i = 0, len = l.length, v; | |
for (; i < len, v = l[i]; i++) { | |
if ( ! fn.prototype[v]) | |
me[v] = function(v) { | |
return function() { | |
Array.prototype.unshift.call(arguments, v+': '); | |
me.log.apply(csl, arguments); | |
} | |
}(v); | |
} | |
}; | |
fn.prototype = csl; | |
fn.prototype.constructor = fn; | |
return new fn; | |
})(root); | |
})(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment