1

In this situation, arguments.callee.name get nothing.

foo = function(){
  console.log(arguments.callee.name);
}

Is there any solution?

kaze13
  • 309
  • 2
  • 12

1 Answers1

0

You didn't name it, thus it has no name.

foo = function(){
  return (arguments.callee.name);
};

bar = function foobar() {
  return (arguments.callee.name);
};

function foobar () {
  return (arguments.callee.name);
}

console.log(foo()); //""
console.log(bar()); //"foobar"
console.log(foobar()) //"foobar"

The difference between foo() and foobar() is that foo() is a function expression, whereas foobar() is a declared function. The difference between foo() and bar() and is that one has a name, the other doesn't. Both are function expressions. Declared functions need a name, function expressions do not. See this canonical question for more info:

var functionName = function() {} vs function functionName() {}

Community
  • 1
  • 1
chiliNUT
  • 18,989
  • 14
  • 66
  • 106