pausing-execution

JavaScript pausing execution of function to wait for user input

倖福魔咒の 提交于 2019-11-27 01:58:42
问题 I'm trying to make a sort of game using the HTML5 canvas, JavaScript and XML. The idea is that you can make a quiz by putting questions and answers in an XML file. I wrote a main loop that loops through all the questions, poses them and checks the correctness of the answer. For now I'm simply using alerts and dialog boxes to answer the questions The problem is that my main loop is one big interconnected whole that walks through the entire game from beginning to end, and instead of having

Proper way to wait for one function to finish before continuing?

心不动则不痛 提交于 2019-11-26 08:47:18
问题 I have two JS functions. One calls the other. Within the calling function, I\'d like to call the other, wait for that function to finish, then continue on. So, for example/pseudo code: function firstFunction(){ for(i=0;i<x;i++){ // do something } }; function secondFunction(){ firstFunction() // now wait for firstFunction to finish... // do something else }; I came up with this solution, but don\'t know if this is a smart way to go about it. var isPaused = false; function firstFunction(){