var k = 0;
function testAl()
{
if (k < 4){
test(k);
k++;
}
if( k < 4) setTimeout(function(){
testAl();
},2000);
}
testAl();
function test(k) {
console.log("来过了=>"+ k);
}
方法二:使用setInterval方法
countDown();//调用下边的方法
var _interval;
var counterTimes = 0;
function countDown() {
_interval = setInterval(scoreCounter, 3000);
function scoreCounter() {
counterTimes++;
if (counterTimes < 4) {
console.log("_flashTimes=>" + counterTimes);
}else {
counterTimes = 0;
clearInterval(_interval);
}
}
}