Skip to content

Instantly share code, notes, and snippets.

@msrafi
Created May 29, 2015 03:05
Show Gist options
  • Save msrafi/6ecbe1a306bb8702036e to your computer and use it in GitHub Desktop.
Save msrafi/6ecbe1a306bb8702036e to your computer and use it in GitHub Desktop.
Function name
<script type="text/javascript">
/* create functions that can report their own names,
by looking into the arguments used to invoke them
*/
function FunctionA(){
var fName = arguments.callee.toString().match(/function ([^\(]+)/)[1]
alert('Hi, I\'m in a function named '+fName)
}
function FunctionB(){
alert(arguments.callee.toString().match(/function ([^\(]+)/)[1]);
}
function FunctionC(){
FunctionA();
FunctionB();
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment