...

View Full Version : Anonymous Function Variable Name to String



David Smith
08-13-2004, 06:22 AM
Hi, I hope you can help me.
But I think this is near on impossible.

The code, cut down:

Function funcMain(funcNumber){
... other code
//First time round, this next statement calls funcOne.
//Second time, it calls funcTwo.
funcNumber("Hello");
}
funcOne = Function(argHello) {
//Code where argHello is used and where I want to be able to
//get the string "funcOne" from the very fact that this is the funcOne
//function, if it is possible.
... code
}
funcTwo = Function(argHello) {
//Same as funcOne.
... code
}
//First, call function funcMain and pass the anonymous function funcOne.
funcMain(funcOne);
//Second, call function funcMain and pass the anonymous function funcTwo.
funcMain(funcTwo);

I could add a string argument to the funcMain call, but that would not be as swift as the way I want it.

Please don't question my reasoning or whether I could do all this in a different way.
I'm only after one thing, whether it is possible to extract the variable name, that was assigned an anonymous function and use it as a string. (in this case funcOne or funcTwo)

I hope I have made sense, but it is quite difficult to explain.

ta muchly,

David Smith

Mr J
08-13-2004, 03:52 PM
Do you mean like this?


<script>
<!--
first_run=1
function funcMain(){
if(first_run==1){
funcOne("Hello");
first_run=0
}
else{
funcTwo("World");
}
}

function funcOne(argHello) {
alert(argHello)
}

function funcTwo(argHello) {
alert(argHello)
}

funcMain();
funcMain();
// -->
</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum