I would like to get the name of the function that called the function.
example.
// the popup will show the source of the function that called the function popup
function popup(str){
calledby = "\r\n" + popup.caller;
alert(calledby);
}
function cheese(){
popup('Hello World!');
}
function onion(){
popup('Hello World!');
}
onion(); // when onion() is called, the output is an alert box with
function onion(){
popup('Hello World!');
}
With the method below
//with this method, no function name is vivible!
popup = {
msg:function(str){calledby = "\r\n" + this.msg.caller; alert(calledby);},
cheese:function(){
this.msg('Hello World!');
},
onion:function(){
this.msg('Hello World!');
}
}
popup.onion(); // when called, the output doesn't show the function name or caller
However, the following is the result of the above method
function (){
this.msg('Hello World!');
}
what I was expecting was...
function popup.msg(){
popup.msg('Hello World!');
}
or similar but it clearly isnt.
All I need is the name of the function that made the call, eg, popup.onion(), I have used toSource, toString, valueOf methods and they either return the body of the source, the [object Object] or undefined.
Can anyone help? or know what I need to do to get the full name of the object and function through the second method, popup.onion() ???
No one has replied yet! Why not be the first?
Sign in or Join us (it's free).