Guest User

Untitled

a guest
Nov 20th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. // functionality is broken across many code snippets wrapped in a function
  2. var array_of_functions = [
  3. function() {
  4. // do something 1
  5. },
  6. function() {
  7. // do something 2
  8. },
  9. function() {
  10. // do something 3
  11. },
  12. function() {
  13. // do something 4
  14. }
  15. ];
  16.  
  17. // Start executing the snippets immediately with a 25 ms lag between each snippet.
  18. setTimeout(function() {
  19. // Get the first code snippet and remove it from the array
  20. var item = array_of_functions.shift();
  21. // execute the next code snippet after 25 ms from now
  22. if (array_of_functions.length > 0) {
  23. setTimeout(arguments.callee, 25);
  24. }
  25. // if the item isn't undefined, execute it
  26. if(item){
  27. item.call();
  28. }
  29. }, 0);
Add Comment
Please, Sign In to add comment