Questions tagged «pausing-execution»

7
等待一项功能完成再继续的正确方法?
我有两个JS函数。一个叫另一个。在调用函数中,我想调用另一个函数,等待该函数完成,然后继续。因此,例如/伪代码: function firstFunction(){ for(i=0;i<x;i++){ // do something } }; function secondFunction(){ firstFunction() // now wait for firstFunction to finish... // do something else }; 我想出了这个解决方案,但不知道这是否是明智的解决方案。 var isPaused = false; function firstFunction(){ isPaused = true; for(i=0;i<x;i++){ // do something } isPaused = false; }; function secondFunction(){ firstFunction() function waitForIt(){ if (isPaused) …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.