-1

この一連の無名関数定義を個別の関数に書き直して、より保守しやすく読みやすくするにはどうすればよいでしょうか? ありがとう!

function animation(){

    var timeout;
    timeout=timeoutsetTimeout(function(){
        console.log('step1')

        timeout=setTimeout(function(){
            console.log('step2')

            timeout=setTimeout(function(){                                  
                console.log('almost there')

                setTimeout(function(){

                        console.log('grand finale')

                    }, 300);

            }, 1000);


        }, 2000);


    }, 5300);
}
4

1 に答える 1

1

handily, you can use closure instead of IOC or DI in JS:

function animation(){

    var timeout;

    function one(){
        console.log('step1');
        timeout=setTimeout(two, 2000);
    }

    function two(){
        console.log('step2');
        timeout=setTimeout(three, 1000);
    }

    function three(){
        console.log('almost there');
        timeout=setTimeout(four, 300);
    }

    function four(){
        timeout=console.log('grand finale');
    }

   return timeout=setTimeout(one, 5300);

}
于 2013-06-17T21:00:22.347 に答える