Timed Code
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script> "use strict"; function timedProcessArray(items, process, callback) { var todo = items.concat(); //create a clone of the original setTimeout(function doSmall() { var start = +new Date(); do { process(todo.shift()); } while (todo.length > 0 && (+new Date() - start < 50)); if (todo.length > 0) { setTimeout(doSmall, 25); } else { callback(items); } }, 25); } function dothing() { timedProcessArray([dothings1, dothings2], function(f) { f(); }, function() { console.log('done1'); }); } function dothings1() { console.log('dothings1') } function dothings2() { console.log('dothings2') } </script> </head> <body> <form id="form1" runat="server"> <div onclick="dothing()"> hello </div> </form> </body> </html>
http://www.nczonline.net/blog/2009/08/11/timed-array-processing-in-javascript/
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/arguments/callee