1

How can I get the function name inside a function in Javascript?

Specifically in Dojo, as this doesn't seem to do the job

arguments.callee.caller
2
  • 1
    arguments.callee.name is what you're looking for, but you should use hard-coded names if you want to be future-friendly. Commented Jul 15, 2013 at 15:19
  • Thanks Dan,arguments.callee.name is undefined. I want to avoid hard coded values. I do have a function name. Commented Jul 15, 2013 at 15:21

2 Answers 2

3

Whether arguments.callee.name is defined or not depends on how the function was defined. It will be defined if the function was defined as Named function expression. Otherwise, you will not have this information.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your response piokuc. I declared my function as follows setmain: function () {...} Its in dojo
That setmain function does not have a name. You can give it a name after the function keyword if you want it to have a name: setmain: function setmain() {...}
1

In dojo, if the function is a method of a class declared through dojo/_base/declare you can get it through :

arguments.callee.nom

See http://dojotoolkit.org/reference-guide/1.9/dojo/_base/declare.html

Every method mixed in by dojo/declare() or safeMixin() is annotated: a special property called nom is added. It contains a name of the method in question and used by inherited() and getInherited() to deduce the name of a superclass method. See safeMixin() for more details.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.