Possible Duplicate:
Javascript how do you find the caller function?
I'm experimenting with javascript/jQuery a bit this morning and was trying to capture the caller name of the currently executing function.
So in the below example, the log would show runMe
as the caller and showMe
as the callee.
jQuery(document).ready(function($) {
function showMe() {
// should log the runMe as the caller and showMe as callee
console.log('Callee: ',arguments.callee)
console.log('Caller: ',arguments.caller);
}
function runMe() {
// getting executed as a button is pressed.
showMe();
}
$('a').bind('click', function(e) {
e.preventDefault();
runMe();
});
});
The above obviously doesn't work, hence my question to you all.
Is there a good way to get the caller in the above example?
please note: I am aware I could get the callee of runMe
and pass it into showMe
as an argument but this question is aiming towards a solution that does not require the caller to be passed into the function 'manually'.
Are there reasons against doing something like this?