When this is null
<p>I am trying to implement a simple queue for functions that take callbacks. My problem is that in the flush method, "this" is null when the action being performed is some long-running thing (in my case, indexedDB calls). I've never experienced this sort of behavior before, so please educate me on what is going on?</p>

<p>Here's the code:</p>

<pre><code>var Queue = (function () {
    function Queue() {
    };

    Queue.prototype.items = [];
    Queue.prototype.results = [];
    Queue.prototype.add = function (action) {
        this.items.push(action);
    };
    Queue.prototype.complete = function () { };
    Queue.prototype.flush = function () {
        var args = Array.prototype.slice.call(arguments);
        if (args.length &gt; 0) { this.results.push(args); }
        if (this.items.length &gt; 0) {
            var action = this.items.shift();
            action.call(this);
        } else { // Complete, call back multi.
            var results = this.results;
            this.clear();
            this.complete(results);
        }
    };
    Queue.prototype.clear = function () {
        this.items = [];
        this.results = [];
    };

    Queue.create = function () {
        return new Queue;
    };

    return Queue;
})();
</code></pre>
