faqts : Computers : Programming : Languages : JavaScript : Language Core : Functions

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

4 of 4 people (100%) answered Yes
Recently 4 of 4 people (100%) answered Yes

Entry

How can I get the name of the Function that called the current Function?

May 12th, 2002 21:49
jsWalter,


This is the only solution I can come up with.
   // mke an array to store function contents
   var y = new Array ();
   // 'currFuncName.caller' returns the ENTIRE contents of the
   // calling function.
   // then split the code line into elements of our array
   y = currFuncName.caller.toString().split( /\n/ );
   // split the first line of the function
   y = y[0].split( / / );
   // This element contains the name of the function
   y = y[1];
   // display the name of the calling function
   alert ( y );
This is not pretty!
Nor can I figure out how to make it as a method!
Can someone show me how to make this better?