Javascript 如何链接多个$.done';s以特定顺序运行函数

Javascript 如何链接多个$.done';s以特定顺序运行函数,javascript,jquery,asynchronous,jquery-events,Javascript,Jquery,Asynchronous,Jquery Events,我正试图按照编写的顺序运行下面的代码,不会跳过它的上一个函数。有办法做到这一点吗?我知道在这里使用jQuery的$.done()会很有用,但我不太确定如何继续,因此非常感谢您的帮助。代码如下: function roundOne () { setTimeout(function () { terminal.echo('Lambda and mu row checks passed. Row ' +(j+1)+ 'found.');

我正试图按照编写的顺序运行下面的代码,不会跳过它的上一个函数。有办法做到这一点吗?我知道在这里使用jQuery的
$.done()
会很有用,但我不太确定如何继续,因此非常感谢您的帮助。代码如下:

function roundOne () {          
    setTimeout(function () { 
        terminal.echo('Lambda and mu row checks passed.  Row ' +(j+1)+ 'found.');
        j++;                     
        if (j < numberOfRowsToFind) {            
            roundOne();            
        }                        
    }, Math.floor((Math.random() * (1500)) + (70 * j)))
}
roundOne(); 

j = 0;
function roundTwo () {          
    setTimeout(function () { 
        terminal.echo('Lambda and mu row checks passed.  Row ' +(j+1)+ ' found.');
        j++;                     
        if (j < numberOfRowsToFind) {            
            roundTwo();            
        }                        
    }, Math.floor((Math.random() * (1500)) + (70 * j)))
}
roundTwo();

j = 0;
function roundThree () {          
    setTimeout(function () { 
        terminal.echo('Lambda and mu row checks passed.  Row ' +(j+1)+ ' found.');
            j++;                     
            if (j < currentSrgValues[0][1]) {            
                roundThree();            
            }                        
    }, Math.floor((Math.random() * (1500)) + (70 * j)))
}
roundThree();          
          
laddaCalculateButton.stop();
函数roundOne(){
setTimeout(函数(){
echo('Lambda和mu行检查通过。行'+(j+1)+'找到');
j++;
如果(j
您可以定义上述所有函数,使它们在上一个函数中运行下一个函数。然后调用
roundOne()
,就完成了

function roundOne () {          
    setTimeout(function () { 
        terminal.echo('Lambda and mu row checks passed.  Row ' +(j+1)+ 'found.');
        j++;                     
        if (j < numberOfRowsToFind) {            
            roundOne();            
        }  else {
            j = 0; // finished, set j=0 and call roundTwo  
            roundTwo();  
        }               
    }, Math.floor((Math.random() * (1500)) + (70 * j)))
}

function roundTwo () {          
    setTimeout(function () { 
        terminal.echo('Lambda and mu row checks passed.  Row ' +(j+1)+ ' found.');
        j++;                     
        if (j < numberOfRowsToFind) {            
            roundTwo();            
        } else {
            j = 0; // finished, set j=0 and call roundThree
            roundThree();     
        }                   
    }, Math.floor((Math.random() * (1500)) + (70 * j)))
}

function roundThree () {          
    setTimeout(function () { 
        terminal.echo('Lambda and mu row checks passed.  Row ' +(j+1)+ ' found.');
            j++;                     
            if (j < currentSrgValues[0][1]) {            
                roundThree();            
            } else {
                laddaCalculateButton.stop(); // finished all the three rounds        
            }            
    }, Math.floor((Math.random() * (1500)) + (70 * j)))
}

j = 0;
roundOne();
函数roundOne(){
setTimeout(函数(){
echo('Lambda和mu行检查通过。行'+(j+1)+'找到');
j++;
如果(j
您可以定义上述所有函数,使它们在上一个函数中运行下一个函数。然后调用
roundOne()
,就完成了

function roundOne () {          
    setTimeout(function () { 
        terminal.echo('Lambda and mu row checks passed.  Row ' +(j+1)+ 'found.');
        j++;                     
        if (j < numberOfRowsToFind) {            
            roundOne();            
        }  else {
            j = 0; // finished, set j=0 and call roundTwo  
            roundTwo();  
        }               
    }, Math.floor((Math.random() * (1500)) + (70 * j)))
}

function roundTwo () {          
    setTimeout(function () { 
        terminal.echo('Lambda and mu row checks passed.  Row ' +(j+1)+ ' found.');
        j++;                     
        if (j < numberOfRowsToFind) {            
            roundTwo();            
        } else {
            j = 0; // finished, set j=0 and call roundThree
            roundThree();     
        }                   
    }, Math.floor((Math.random() * (1500)) + (70 * j)))
}

function roundThree () {          
    setTimeout(function () { 
        terminal.echo('Lambda and mu row checks passed.  Row ' +(j+1)+ ' found.');
            j++;                     
            if (j < currentSrgValues[0][1]) {            
                roundThree();            
            } else {
                laddaCalculateButton.stop(); // finished all the three rounds        
            }            
    }, Math.floor((Math.random() * (1500)) + (70 * j)))
}

j = 0;
roundOne();
函数roundOne(){
setTimeout(函数(){
echo('Lambda和mu行检查通过。行'+(j+1)+'找到');
j++;
如果(j
您可以定义上述所有函数,使它们在上一个函数中运行下一个函数。然后调用
roundOne()
,就完成了

function roundOne () {          
    setTimeout(function () { 
        terminal.echo('Lambda and mu row checks passed.  Row ' +(j+1)+ 'found.');
        j++;                     
        if (j < numberOfRowsToFind) {            
            roundOne();            
        }  else {
            j = 0; // finished, set j=0 and call roundTwo  
            roundTwo();  
        }               
    }, Math.floor((Math.random() * (1500)) + (70 * j)))
}

function roundTwo () {          
    setTimeout(function () { 
        terminal.echo('Lambda and mu row checks passed.  Row ' +(j+1)+ ' found.');
        j++;                     
        if (j < numberOfRowsToFind) {            
            roundTwo();            
        } else {
            j = 0; // finished, set j=0 and call roundThree
            roundThree();     
        }                   
    }, Math.floor((Math.random() * (1500)) + (70 * j)))
}

function roundThree () {          
    setTimeout(function () { 
        terminal.echo('Lambda and mu row checks passed.  Row ' +(j+1)+ ' found.');
            j++;                     
            if (j < currentSrgValues[0][1]) {            
                roundThree();            
            } else {
                laddaCalculateButton.stop(); // finished all the three rounds        
            }            
    }, Math.floor((Math.random() * (1500)) + (70 * j)))
}

j = 0;
roundOne();
函数roundOne(){
setTimeout(函数(){
echo('Lambda和mu行检查通过。行'+(j+1)+'找到');
j++;
如果(jfunction runRounds(msg, limits) {
    var j = 0;
    var limit = limits.shift();

    function run() {
        setTimeout(function () { 
            terminal.echo(msg.replace("%d", j+1));
            j++;                     
            if (j < limit) {            
                run();            
            } else {
                // done with round - if more to go, run again
                if (limits.length) {
                    runRounds(limits);
                }

            }
        }, Math.floor((Math.random() * (1500)) + (70 * j)))
    }
    run();
}

runRounds('Lambda and mu row checks passed.  Row %d found.', [numberOfRowsToFindInRoundOne, numberOfRowsToFindInRoundOne, currentSrgValues[0][1]]);