Today I Learned

hashrocket A Hashrocket project

Get current call stack with `new Error().stack`

arguments.caller use to be an acceptable way to find what function is calling the current function. Now, if 'use strict'; has been called for the current closure then an error will be thrown preventing the arguments.caller call.

Getting the current stack trace is just as easy though with new Error().stack.

function whoCalledMe() {
  console.log(new Error().stack);
  //doin' somethin'
See More #javascript TILs
Looking for help? At Hashrocket, our JavaScript experts launch scalable, performant apps on the Web, Android and iOS. Contact us and find out how we can help you.