title: Asynchronous method queue in Javascript
body: <p>I am attempting to implement an asynchronous method queue in Javascript as seen in <a href="http://www.dustindiaz.com/async-method-queues/" rel="nofollow">this blog post</a></p>
  
  <p>Here's what I have so far:</p>
  
  <pre><code>function Queue() {
    this._methods = [];
    this._response = null;
    this._flushed = false;
  }
  
  (function(Q){
  
    Q.add = function (fn) {
      if (this._flushed) fn(this._response);
      else this._methods.push(fn);
    }
  
    Q.flush = function (response) {
      if (this._flushed) return;
      this._response = response;
      while (this._methods[0]) {
        this._methods.shift()(response);
      }
      this._flushed = true;
    }
  
  })(Queue.prototype);
  </code></pre>
  
  <p>I can't seem to get it to work as advertised, although the code looks correct to me. When I call the flush function I get <code>this._methods is undefined</code> on the line <code>while (this._methods[0]) {</code>.</p>