Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mingliangfeng/214f2edcbf160c873603ea26a22d4cb3 to your computer and use it in GitHub Desktop.
Save mingliangfeng/214f2edcbf160c873603ea26a22d4cb3 to your computer and use it in GitHub Desktop.
print stack trace anywhere
function foo(args) {
var i, j, k;
// ...
// j acquires some interesting value
// Who called foo when j took this interesting value?
//
var e = new Error('dummy');
var stack = e.stack.replace(/^[^\(]+?[\n$]/gm, '')
.replace(/^\s+at\s+/gm, '')
.replace(/^Object.<anonymous>\s*\(/gm, '{anonymous}()@')
.split('\n');
console.log(stack);
// ...
// rest of the code
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment