I have the following code:
$(document).ready(funcA);
function funcA(){
funcB();
}
function funcB(){
//some code
}
On the funcB
, I want to know if it was called by the $(document).ready
event or not.
It is any way I can do this?
I have the following code:
$(document).ready(funcA);
function funcA(){
funcB();
}
function funcB(){
//some code
}
On the funcB
, I want to know if it was called by the $(document).ready
event or not.
It is any way I can do this?
arguments.caller
gives you the function that made the call.
You can compare it to a function, like so
if(arguments.caller == funcA)
since functions are types of variables. You can then do a loop that takes the arguments.caller
of the arguments.caller
and trace the route until you get null
.
However, this is a non-standard feature and likely will not work
You might want to re-write all your functions so that they pass on a message to the funcB
function, like this
What I mean is that you do this (or something with the same principle)
$(document).ready(function(){funcA("called by event listener")});
funcA(message){
funcB(message);
}
funcB(message){
if(message == "called by event listener") alert("Came from event listener");
}
Note that you do not have to name the arguments (in case you do not want to clutter everything), if you use arguments[arguments.length - 1]
. arguments
is an array of all arguments.
You could also try and mess around with the Function
prototype, and try to make every function call pass along the last argument that it received, so that you do not have to do it yourself.