Skip to content

Instantly share code, notes, and snippets.

@tigerclaw-az
Created January 18, 2014 04:03
Show Gist options
  • Save tigerclaw-az/8486017 to your computer and use it in GitHub Desktop.
Save tigerclaw-az/8486017 to your computer and use it in GitHub Desktop.
JavaScript debugging helper functions
/**
* Defines the start point of a debugging section
* @param {string} what Decription of debug section [optional]
* @example
* console.beginDebugging(); // Will try to use the function name as description
* console.beginDebugging('my method'); // Uses 'my method' as description
*/
console.beginDebugging = function beginDebugging(what) {
var caller = console.beginDebugging.caller,
title;
while (caller && caller.name) {
title = title ? title + ' < ' + caller.name : caller.name;
caller = caller.caller;
}
console.groupCollapsed(what || title);
console.time(console.beginDebugging.caller.name + ' completed in');
console.groupCollapsed(' [stack trace]');
console.trace();
console.groupEnd();
};
/**
* Defines the end point of a debugging section
* @example
* console.endDebugging();
*/
console.endDebugging = function endDebugging() {
console.timeEnd(console.endDebugging.caller.name + ' completed in');
console.groupEnd();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment