Created
November 9, 2018 21:39
-
-
Save stewartmcgown/0d898ed17b19218d4f087575a0809648 to your computer and use it in GitHub Desktop.
Get an array of the JavaScript callstack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class test { | |
static isPrivate() { | |
let callername; | |
try { | |
throw new Error(); | |
} catch (e) { | |
/** @type {String[]} */ | |
let stack = e.stack.split("\n"); | |
let out = []; | |
for (let i = 0; i < stack.length; i++) { | |
if (i == 0 || i == stack.length - 1) continue; | |
out.push( | |
stack[i] | |
.replace("at", "") | |
.replace(/ *\([^)]*\) */g, "") | |
.trim() | |
); | |
} | |
console.dir(out); | |
} | |
} | |
static one() { | |
this.isPrivate(); | |
} | |
static two() { | |
this.one(); | |
} | |
static three() { | |
this.two(); | |
} | |
static four() { | |
this.three(); | |
} | |
} | |
(initial = () => test.four())(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment