Web Analytics Made Easy -
StatCounter how to fill array with functions? - CodingForum

Announcement

Collapse
No announcement yet.

how to fill array with functions?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to fill array with functions?

    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?

  • #2
    x = new Array('foo1()'.'foo2()'.'foo3()');

    //call foo1()
    eval(x[0]);

    //call foo2()
    eval(x[1]);

    //rinse ... repeat
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

    Comment


    • #3
      how do you mean?

      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.

      Comment


      • #4
        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.
        Last edited by ASAAKI; Jul 9, 2002, 02:11 PM.
        'If you don't stand for something, you'll fall for anything.'

        Comment


        • #5
          <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>

          Comment

          Working...
          X