console.trace() outputs its result on console. I want to get the results as string and save them to a file. I don\'t define names for functions and
console.trace()
you only need var stack = new Error().stack. this is simplified version of @sgouros answer.
var stack = new Error().stack
function foo() { bar(); } function bar() { baz(); } function baz() { console.log(new Error().stack); } foo();
Probably will not work in every browser (works in Chrome).