Major bug: call does not remove
funcArr[name]
after iterating them so if you add something to the "first" queue and call the first queue, adding something to the first queue will still have the functions from before you called the queue earlier. I created a (demo of the issue); as you see the alert will be shown twice asfuncArr[name]
is never emptiedYou're storing keys (function names) in the array
funcArr
.funcArr
should be a hash object rather than an array.You're using
for..in
on an array (why this is badwhy this is bad) and moreover, the variablefunc
will be global. Use a regular for loop instead here. I'd recommend using$.each
here. With$.each
you'd write the loop$.each(funcArr, function(i, fn) { var dfd = $.Deferred(); fn(dfd); promiseArr.push(dfd.promise()); });
You're module pattern seems off... 1) its common convention that a class name should be capitalized, ie
MyQueue
, 2) theres no real reason to use thethis
keyword if you're not planning to add these functions on prototype, 3) Inthis.start
your linethis.call(ord.pop());
is a bit confusing.
As you were not making use of prototype in your function I adapted your code to use the "module pattern". This allows your module to be created without thenew
keyword whereas before it would of caused major issues.