is there way to fill array wite functions ?
i mean if i have the array x(3)
and 3 functions foo0(),foo1(),foo2()
i like to somehow fill the x array with this 3 functions.
is there way?
Vladdy
07-09-2002, 07:03 PM
x = new Array('foo1()'.'foo2()'.'foo3()');
//call foo1()
eval(x[0]);
//call foo2()
eval(x[1]);
//rinse ... repeat :thumbsup:
Soldier Bob
07-09-2002, 07:05 PM
I believe I understand the programming structure you want to make.
But let me just clarify.
Do you mean place the names of the functions into an array so that a function can be called by an array lookup?
or do you mean placing the whole function into an array for something like a retrival system?
if I remember correctly you can cobble together statements from variables that call functions.
so that you could call func01 -func10, If those were the names of the functions by adding the suffix 'i'. if 'i' was a counter in a loop.
---PSEUDO CODE---
for (i=1;i<11;i++) {
eval('func' + i + '()');
}
---PSEUDO CODE---
something like that (I didnt test this yet)
what exactly are you doing with the functions?
-S Bob.
ASAAKI
07-09-2002, 07:08 PM
maybe this'll work
for(var i=0;i<3;i++){
x[i]="foo"+i+"()";
}
it should get x to store the names of the three funtions.
adios
07-09-2002, 10:45 PM
<html>
<head>
<title>untitled</title>
<script type="text/javascript" language="JavaScript">
function foo0() {alert('foo0')}
function foo1() {alert('foo1')}
function foo2() {alert('foo2')}
var x = new Array(foo0, foo1, foo2);
x[0]();
x[1]();
x[2]();
</script>
</head>
<body>
</body>
</html>