chaining async method calls - javascript
<p>You have a prototype object Foo with two async method calls, bar and baz.</p>

<pre><code>var bob = new Foo()

Foo.prototype.bar = function land(callback) {
  setTimeout(function() {
    callback()
    console.log('bar');
  }, 3000);
};

Foo.prototype.baz = function land(callback) {
  setTimeout(function() {
    callback()
    console.log('baz');
  }, 3000);
};
</code></pre>

<p>We want to do bob.bar().baz() and have it log "bar" and "baz" sequentially.</p>

<p>If you cannot modify the method calls (including passing in your callback function), how can you pass a default callback into these method calls? </p>

<p>Some ideas:</p>

<ol>
<li><p>Wrap "bob" with decorator (still fuzzy on how to implement, could use a small example)</p></li>
<li><p>Modify constructor to assign default callback if none assigned (have not considered if this is possible or not)</p></li>
<li><p>Use a generator wrapper that will continue to call next method until none are left?</p></li>
</ol>