When using JSDeferred you may want to return something immediately. For example if the result was already cached.

The first attempt might look like this:

function doSomething() {
  var deferred = new Deferred();
  deferred.call("the result");
  return deferred;
}

doSomething().next(function(result) {
  console.log(result);
};

The problem of course is that the next function will not have been assigned yet. Fortunately the solution is fairly simple:

function doSomething() {
  return Deferred.next(function() {
    return "the result";
  });
}