/ Published in: JavaScript
// create a variable to toggle debugging
// to use it, just call debug(with,any,optional,parameters)
debug(x,y,z);
// it will try to guess what type of message to log, or you can specify in the first parameter
debug("error",x,y,z);
// to use it, just call debug(with,any,optional,parameters)
debug(x,y,z);
// it will try to guess what type of message to log, or you can specify in the first parameter
debug("error",x,y,z);
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// create a variable to toggle debugging var debugMode = true; function debug() { if (debugMode===true) { var x = "debug", a = arguments.length ? arguments : ["debug"]; var c = ["error","warn","info","log","debug"]; var t = c.some ? (c.some(function(v) { return x = (a[0].indexOf(v)>-1) ? v : false; }))||x : x; return console[(x||t)](arguments); } }