...

View Full Version : how can i know from what function function call was invoked?



frontline
07-08-2003, 10:18 AM
Hello
i have
function foo(){
blah()
}

how can i know in function blah() that it was called from function foo()?
(and not from other function )

thanks

Kor
07-08-2003, 11:07 AM
hm... it depends why you need that for... Try using a parameter in fuction foo(param) with an if staement or whichever. Something like

function foo(param){
if(param = 'blabla'){
blah()
}
}
.
.
.
<tag onclick="foo('blabla')">

If you can be more specific....

frontline
07-08-2003, 11:21 AM
well of course you can add indictor as arg , but this is not the case here
i can't add args (dont ask why i just can't ) .

Kor
07-08-2003, 11:30 AM
Than give the blah() an argument and use that as a sort of separator later (blah with and without arg...)

function foo(){
blah('arg')
}

Still don't see the final point of your need...

ahosang
07-08-2003, 01:12 PM
Use the callee property:
<html>
<head>
<script>
function foo() {
blah();
}
function blah() {
var c=arguments.callee.caller;// gets the caller
if (c==foo) {
alert("Called from foo()");
} else {
alert("Called otherwise");
}
}
</script>
</head>

<body>
<form>
<input type="button" value="Call blah() directly" onclick="blah()">
<br><br>
<input type="button" value="Call blah() through foo()" onclick="foo()">
</form>
</body>
</html>

frontline
07-08-2003, 01:56 PM
Great!
tnx



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum