@isaacs answer is correct, but if you need more specific or cleaner error stack, you can use this function:
function getCleanerStack() {
var err = new Error();
Error.captureStackTrace(err, getStack);
return err.stack;
}
This function is inspired directly from the console.trace
function in NodeJS.
Source code: Recent version or Old version.