Last active
September 22, 2017 20:28
-
-
Save ryaninvents/d866746296148cef94f6592ddc845882 to your computer and use it in GitHub Desktop.
Quick debugging for JS functions
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
function debug(fn) { | |
return function () { | |
console.groupCollapsed(fn.name); | |
console.debug('Args:', arguments); | |
const result = fn.apply(this, arguments); | |
console.debug('Returns:', result); | |
console.groupCollapsed('Stack'); | |
console.log(new Error().stack.split('\n').slice(1).join('\n')); | |
console.groupEnd(); | |
console.groupEnd(); | |
return result; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment