The function in your code snippet has no name, it's anonymous. The property it's assigned to on profile
has a name (edit
), but the function does not. No, there is no way to get edit
or profile.edit
or Cube.profile.edit
from the function object.
You can give the function a name:
Cube : {
profile: {
edit : function edit(){
alert(arguments.callee.name);
}
}
}
...but that's using a named function expression which will create two separate function objects on IE8 and earlier.
You can also do this:
Cube : {
profile: {
edit : Cube_profile_edit
}
}
// ...
function Cube_profile_edit(){
alert(arguments.callee.name);
}
However, in all of the above, two problems:
You're using arguments.callee
which is both very slow on a lot of browsers, and not valid in strict mode.
The name
property of function objects is non-standard, which is why this answer talks about possibly having to parse the result of Function#toString
. The problem is, Function#toString
is also non-standard (but fairly broadly supported, except on mobile browsers).
You could avoid that second problem by searching through the Cube
object graph for the property that refers to the function, but that would still require using arguments.callee
(unless you give the function a real name and then use that real name when searching to find the property path that leads to it).