Skip to content

Instantly share code, notes, and snippets.

@ofca-snippets
Created December 30, 2012 13:39
Show Gist options
  • Save ofca-snippets/4412846 to your computer and use it in GitHub Desktop.
Save ofca-snippets/4412846 to your computer and use it in GitHub Desktop.
Safe, simple and cross browser (I hope) version of console.log
(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