Skip to content

Instantly share code, notes, and snippets.

@listenrightmeow
Created April 11, 2012 01:01
Show Gist options
  • Save listenrightmeow/2356046 to your computer and use it in GitHub Desktop.
Save listenrightmeow/2356046 to your computer and use it in GitHub Desktop.
log
log = function (kwargs) {
try {
var console = window.console,
debug =
window.location.toString().indexOf('_mode=debug') !== -1;
kwargs = $.extend({
name: '',
id: '',
args: []
}, kwargs);
kwargs.args = Array.prototype.slice.call(kwargs.args);
kwargs.args.splice(0, 0, '[{{ id }}] {{ name }}()'
.replace('{{ id }}', kwargs.id)
.replace('{{ name }}', kwargs.name));
if (console && $.isFunction(console.log) && debug) {
if ((navigator.userAgent.indexOf('WebKit') !== -1) ||
/ Mobile\//.test(navigator.userAgent)) {
/* an attempt to .apply or .call console.log like a
* normal js function in webkit results in the error:
* TypeError: Illegal invocation
*/
console.log(kwargs.args);
} else {
console.log.apply(console, kwargs.args);
}
}
} catch (e) {}
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment