Dies ist der Code:setTimeout nicht innerhalb der Karte ausgeführt? oder setTimeOut auf Kartenfunktion?
while(countLoop < count) {
let randIndex = Math.floor(Math.random()*4); // returns // 1 to 3 decimal, this will be used for colors indexes
console.log("while true count = ",randIndex)
this.setState(
({colorsChallengeForUser}, props) => ({
colorsChallengeForUser: [...colorsChallengeForUser, randIndex]
}),
() => { // setState has a default callback we make use of that here.
let { colorsChallengeForUser } = this.state;
colorsChallengeForUser.map((item, index, array) => {
switch(item) {
case 0:
// red.play()
setTimeout(red.play(), 3000);
break;
case 1:
// green.play()
setTimeout(green.play(), 3000);
break;
case 2:
// yellow.play()
setTimeout(yellow.play(), 3000);
break;
case 3:
// yellow.play() // this wo
setTimeout(blue.play(), 3000);
break;
defalt:
console.error(`Unknown ${item}`);
}
});
}
);
countLoop++;
}
alle Werke, sondern setzen eine Auszeit funktioniert nicht, sie alle zugleich auf js Bewertung spielen. Wie mache ich die Map-Ausführung mit setTimeOut langsamer?
'setTimeout (red.play(), 3000);' läuft sofort ... 'setTimeout (red.play, 3000) ; 'würde' red.play() 'ausführen, wenn das Zeitlimit abgelaufen ist ... P.S. Warum verwenden Sie '.map', wenn die Callback-Funktion nichts zurückgibt? Verwenden Sie stattdessen ".forEach" –
Wenn 'red.play()' eine Funktion zurückgibt, sollten Sie @ JaromandaX advise folgen. – Redu
wahr (unwahrscheinlich) –