question about cycling through a series of functions

Discussion in 'Javascript' started by Julia Briggs, Feb 20, 2005.

  1. Julia Briggs

    Julia Briggs Guest

    How would I create another function that would cycle sequentially
    through each of these? like 1..,2..,3,..4,..1,..etc..

    function1() { something }
    function2() { something }
    function3() { something }
    function4() { something }
    Julia Briggs, Feb 20, 2005
    #1
    1. Advertising

  2. "Julia Briggs" <> wrote in message
    news:...
    > How would I create another function that would cycle sequentially
    > through each of these? like 1..,2..,3,..4,..1,..etc..
    >
    > function1() { something }
    > function2() { something }
    > function3() { something }
    > function4() { something }
    >



    function5()
    {
    loop
    call the other functions
    end loop
    }


    MK
    The Mighty Krell, Feb 20, 2005
    #2
    1. Advertising

  3. Julia Briggs

    Ivo Guest

    "The Mighty Krell" wrote
    > "Julia Briggs" wrote
    > > How would I create another function that would cycle sequentially
    > > through each of these? like 1..,2..,3,..4,..1,..etc..

    <snip>
    Using eval():

    function fun1() { alert( 'Greetings from function ' + 1); }
    function fun2() { alert( 'Hello from function ' + 2); }
    function fun3() { alert( 'Hi from function ' + 3); }

    function go() {
    for( var i=1; i<4; i++ ) {
    eval( 'fun' + i + '()' );
    }
    }
    go();

    Loop through function go() as often as you like.
    hth
    --
    Ivo
    Ivo, Feb 20, 2005
    #3
  4. "Ivo" <> wrote in message
    news:4218ee50$0$36063$...
    > "The Mighty Krell" wrote
    > > "Julia Briggs" wrote
    > > > How would I create another function that would cycle sequentially
    > > > through each of these? like 1..,2..,3,..4,..1,..etc..

    > <snip>
    > Using eval():
    >
    > function fun1() { alert( 'Greetings from function ' + 1); }
    > function fun2() { alert( 'Hello from function ' + 2); }
    > function fun3() { alert( 'Hi from function ' + 3); }
    >
    > function go() {
    > for( var i=1; i<4; i++ ) {
    > eval( 'fun' + i + '()' );
    > }
    > }
    > go();
    >
    > Loop through function go() as often as you like.
    > hth
    > --
    > Ivo



    Why in the world would you use eval for something this trivial?
    The Mighty Krell, Feb 20, 2005
    #4
  5. Julia Briggs

    Randy Webb Guest

    The Mighty Krell wrote:
    > "Ivo" <> wrote in message
    > news:4218ee50$0$36063$...
    >
    >>"The Mighty Krell" wrote
    >>
    >>>"Julia Briggs" wrote
    >>>
    >>>>How would I create another function that would cycle sequentially
    >>>>through each of these? like 1..,2..,3,..4,..1,..etc..

    >>
    >><snip>
    >>Using eval():
    >>
    >>function fun1() { alert( 'Greetings from function ' + 1); }
    >>function fun2() { alert( 'Hello from function ' + 2); }
    >>function fun3() { alert( 'Hi from function ' + 3); }
    >>
    >>function go() {
    >> for( var i=1; i<4; i++ ) {
    >> eval( 'fun' + i + '()' );
    >> }
    >>}
    >>go();
    >>
    >>Loop through function go() as often as you like.
    >>hth
    >>--
    >>Ivo

    >
    >
    >
    > Why in the world would you use eval for something this trivial?


    Not that its "trivial". But why use it when its not needed?


    function go(){
    for (var i=1; i<4; i++){
    window['fun'+i]()
    }
    }



    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Randy Webb, Feb 20, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JoeC
    Replies:
    5
    Views:
    401
  2. JoeC
    Replies:
    1
    Views:
    315
  3. JoeC
    Replies:
    0
    Views:
    338
  4. Dieter Faulbaum

    cycling through options

    Dieter Faulbaum, Mar 16, 2010, in forum: Python
    Replies:
    0
    Views:
    260
    Dieter Faulbaum
    Mar 16, 2010
  5. Dan Quill
    Replies:
    0
    Views:
    105
    Dan Quill
    Apr 2, 2004
Loading...

Share This Page