Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get current function name 1

Status
Not open for further replies.

partymong

Programmer
Nov 5, 2003
39
0
0
GB
Hi All,
Is there a way of retrieving the name of the currently running function?

i.e function x is running and within that function I want to return it's name. Return x (the name of the function)

Thankyou in advance for your help
 
This works for me, although I suspect there are other ways. You should check on the compatibility of "arguments.callee" before using it for any crucial purpose, of course.

Code:
<html>
<head>
	<script type="text/javascript">
	<!--

		function someFunc() {
			var ownName = arguments.callee.toString();
			ownName = ownName.substr('function '.length);		// trim off "function "
			ownName = ownName.substr(0, ownName.indexOf('('));		// trim off everything after the function name
			alert(ownName);
		}

		someFunc();
	//-->
	</script>
</head>
</html>

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top