-
identify the name of a function from within the function itself
is there any way to identify and return the name of a function from within the function itself???
i.e. if i create the function -- testFunc() -- is there any code i can put in testFunc() that will return the name of the function, "testFunc"
using "typeof" or "this" does not seem to work
is this possible???
the reason i want to do this is for debugging purposes
-
You can reference to function itself by using arguments.callee property. Using arguments.caller will return a reference to the function which called current function or null if there is no such a function.
Never give up...
-
Hmmm...i tried this
testing();
function testing () {
trace(arguments.callee);
}
and trace gave me this for the output, [type Function].
What I was hoping for was the actual name of the function, "testing".
What am I doing wrong???
-
I don't know your requirements but if you have a reference to the function itself it will help you in almost all cases. Why it is better than to know it's name? Because you can call it instantly without issues of calling a function by it's name (to be honest I can say that I do not remember how to do it, I was forced to do it only once).
Function class methods also will help you to apply a function to an object so this keyword will reference to whatever you want.
I consider that is enough to solve most of the problems.
But your question sounds interesting if I'll find a solution I'll post it here. But in the long run I recommend you to use Function class' methods.
Never give up...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|