JavaScript, webdev

Javascript – Print Stack Trace

Simple and short code to drop a stack trace to your console and/or page.

var e = new Error('dummy');
var stack = e.stack.replace(/^[^\(]+?[\n$]/gm, '')
  .replace(/^\s+at\s+/gm, '')
  .replace(/^Object.\s*\(/gm, '{anonymous}()@')
  .split('\n');
console.log(stack);

and here you can play with a working demo on JSbin

Standard

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s