Skip to content

Instantly share code, notes, and snippets.

@ryaninvents
Last active September 22, 2017 20:28
Show Gist options
  • Save ryaninvents/d866746296148cef94f6592ddc845882 to your computer and use it in GitHub Desktop.
Save ryaninvents/d866746296148cef94f6592ddc845882 to your computer and use it in GitHub Desktop.
Quick debugging for JS functions
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