Javascript Queue Object I created a Queue object when answering this question and I was wondering if it could do with some improvement.

Here is the current code:

var Queue = (function () {

    Queue.prototype.autorun = true;
    Queue.prototype.running = false;
    Queue.prototype.queue = [];

    function Queue(autorun) {
        if (typeof autorun !== "undefined") {
            this.autorun = autorun;
        }
        this.queue = []; //initialize the queue
    };

    Queue.prototype.add = function (callback) {
        var _this = this;
        //add callback to the queue
        this.queue.push(function () {
            var finished = callback();
            if (typeof finished === "undefined" || finished) {
                //  if callback returns `false`, then you have to 
                //  call `next` somewhere in the callback
                _this.dequeue();
            }
        });

        if (this.autorun &amp;&amp; !this.running) {
            // if nothing is running, then start the engines!
            this.dequeue();
        }

        return this; // for chaining fun!
    };

    Queue.prototype.dequeue = function () {
        this.running = false;
        //get the first element off the queue
        var shift = this.queue.shift();
        if (shift) {
            this.running = true;
            shift();
        }
        return shift;
    };

    Queue.prototype.next = Queue.prototype.dequeue;

    return Queue;

})();


Is there anything that I can expand on or improve in this Object? 
Should anything be changed?
Overall, the code is quite simple. That's a good thing already.

Some things can be improved though:


Always create the autorun property. It will help your compiler. See here 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 === undefined is enough because you know for sure the identifier exists.
var shift = this.queue.shift(); w-w-w-what's this variable name?! You probably mean var first .... Use descriptive variable names.
I'm not sure you want to return shift in dequeue. Don't you mean this? Chaining is fun!