Function simulation of different functions in synchronization
funcList is the queue of function execution functions, where flag=true in the callback function is the synchronous marker quantity
<script>var flag = false;function funcTest(t,func){ setTimeout(function(){ (function(param){ console.log(param); func(); }(t)); },t*1000);}var funcList = [];funcList.push(function(){ funcTest(4,function(){ flag = true;//Synchronous marker})});// Different asynchronous functions are added to the queue funcList.push(function(){ funcTest(3,function(){ flag = true;})});//Add different asynchronous functions into the queue funcList.push(function(){funcTest(2,function(){ flag = true;})});//Add different asynchronous functions into the queue dealFuncSync(funcList);function dealFuncSync(funcList){ function callBackSync(){ if(!funcList||funcList.length==0){ console.log('end'); return; } flag = false; funcList.shift()(); setTimeout(function(){ if(flag) {//Control queue function synchronization callBackSync(); }else{ setTimeout(arguments.callee,100); } },100); } callBackSync();}</script>The above method of implementing synchronous js asynchronous function in different articles is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.