A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: identify the name of a function from within the function itself

  1. #1
    Junior Member
    Join Date
    Feb 2001
    Posts
    22

    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

  2. #2
    Novemberain Master
    Join Date
    Sep 2004
    Location
    Void
    Posts
    390
    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...

  3. #3
    Junior Member
    Join Date
    Feb 2001
    Posts
    22
    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???

  4. #4
    Novemberain Master
    Join Date
    Sep 2004
    Location
    Void
    Posts
    390
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center