Created
April 11, 2012 01:01
-
-
Save listenrightmeow/2356046 to your computer and use it in GitHub Desktop.
log
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
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