How can I get the name of function inside a JavaScript function?

pencilCake picture pencilCake · Jan 29, 2010 · Viewed 21.8k times · Source

How is it possible to learn the name of function I am in?

The below code alerts 'Object'. But I need to know how to alert "Outer."

function Outer(){

    alert(typeof this);

}

Answer

yannis picture yannis · Jan 29, 2010

This will work:

function test() {
  var z = arguments.callee.name;
  console.log(z);
}