Created
March 24, 2019 12:01
-
-
Save tanhauhau/1590f036d012fd01fdef7f0b27e0638a to your computer and use it in GitHub Desktop.
throw an error to get stack
This file contains hidden or 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
let _value; | |
Object.defineProperty(obj, 'awesome', { | |
get: () => { | |
try { | |
// intentionally throw an Error to get the call stack | |
throw new Error(); | |
} catch (error) { | |
// stack is the stack trace, | |
// containing error message and the stack | |
const stack = error.stack; | |
// print the callee stack | |
console.log( | |
stack | |
.split('\n') | |
.slice(2) | |
.join('\n') | |
); | |
} | |
return _value; | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment