Created
January 18, 2014 04:03
-
-
Save tigerclaw-az/8486017 to your computer and use it in GitHub Desktop.
JavaScript debugging helper functions
This file contains 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
/** | |
* 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