내 proble은 setintervall 함수에 관한 것입니다. first()
및 second()
실행이 완료되면 thrice()
이라는 함수를 호출합니다. 저것에 proble가 없다. 아래의 코드 :자바 스크립트 중지 간격 및 동작
var oneFinish = false;
var twoFinish = false;
function first() {
console.log("FUNCTION first RUNNING");
for (i = 0; i < 5; i++) {
console.log("first " + i);
}
console.log("FUNCTION first FINISH");
oneFinish = true;
}
function second() {
console.log("FUNCTION second RUNNING");
for (i = 0; i < 10; i++) {
console.log("second " + i);
}
console.log("FUNCTION second FINISH");
twoFinish = true;
}
function thrice() {
var intev = setInterval(function() {
if (oneFinish && twoFinish) {
console.log("FUNCTION thrice RUNNING");
oneFinish = false;
twoFinish = false;
clearInterval(intev);
}
}, 3000);
console.log("FUNCTION thrice FINISH");
}
first();
second();
thrice();
결과는 다음과 같다 :
당신은 출력의 끝에 볼FUNCTION first RUNNING
first 0
first 1
first 2
first 3
first 4
FUNCTION first FINISH
FUNCTION second RUNNING
second 0
second 1
second 2
second 3
second 4
second 5
second 6
second 7
second 8
second 9
FUNCTION second FINISH
FUNCTION thrice FINISH
FUNCTION thrice RUNNING
, 그것은 문제 FUNCTION thrice FINISH
당신 때문입니다 FUNCTION thrice RUNNING
당신은 비동기에 대해 들었습니다? –
예, 들었습니다. 왜 downvote? 더 많은 설명을 원하십니까? 아니면 질문을 왜 싫어하는거야? – Aroniaina