Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

loggable()

View gist:547926
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/**
* Loggable adds a log method to the passed object.
* @param obj {Object} Object which will get a new log() method
* @param objName {String} Optional parameter for displaying a string before each log output
* @param debugMode {boolean} Optional switch for disabling logging
*/
var loggable = function(obj /* , objName, debugMode */){
var objName = arguments[1] || "",
debugMode = (typeof arguments[2]!=="undefined") ? arguments[2] : true;
prefix = objName ? objName + ": " : "";
obj.log = (function(prefix){
return function(){
if (debugMode && typeof console!=="undefined"){
if (arguments.length){
arguments[0] = prefix + arguments[0];
}
console.log.apply(null, arguments);
}
}
})(prefix);
return obj;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.