Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jun 2002
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 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
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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"

  • #3
    New Coder
    Join Date
    Jul 2002
    Location
    USA, East Coast
    Posts
    43
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question 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.

  • #4
    Regular Coder
    Join Date
    Jul 2002
    Location
    This little Earth.
    Posts
    383
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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; 07-09-2002 at 07:11 PM.

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    <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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •