Overall, the code is quite simple. That's a good thing already.
Some things can be improved though:
Always create the
autorunproperty. It will help your compiler. See herehere for more details. Besides, it's simpler to read. Just go with this:function Queue(autorun) { this.autorun = autorun; }
On another note, adding the properties on the prototype is just as bad, read the link I already showed to understand why.
- Maybe it's only me, but the first lines are disturbing because they're before the "class" declaration. So it looks like they belong to the external object, while they actually belong to the hoisted function.
- You don't need
typeof variable === "undefined".variable === undefinedis enough because you know for sure the identifier exists. var shift = this.queue.shift();w-w-w-what's this variable name?! You probably meanvar first .... Use descriptive variable names.- I'm not sure you want to return
shiftindequeue. Don't you meanthis? Chaining is fun!