Javascript functions queue -


i writing application in javascript , jquery , need follow sequential order on functions calls, i've thought in using queue. have seen this, (if possible) prefer abstract or avoid function(next) in function calls example below because have lot of custom functions:

var fn1 = function(next){     console.log("i fn1");     next(); };  

is possible or there alternative , don't know it?

none of tested, but... set array of functions , iterate through them:

var fn1 = function(){ code here }; var fn2 = function(){ code here }; var functionqueue = [ fn1, fn2 ]; $.each(function(functionqueue, functionitem){ functionitem(); }); 

or, if wanted have 'next()' function, do:

var fn1 = function(){ code here }; var fn2 = function(){ code here }; var functionindex 0; var functionqueue = [ fn1, fn2 ]; var next = function(){ functionqueue[functionindex++]() } 

Comments

Popular posts from this blog

java - BeanIO write annotated class to fixedlength -

Using Java 8 lambdas/transformations to combine and flatten two Maps -

How to connect android app to App engine -