Deferred execution order

Deferred execution order

When creating a new Deferred object, if I attach handlers in the following order:

  1. var x = $.Deferred();

  2. x.done(function () { console.log('done 1'); });
  3. x.always(function () { console.log('always 1'); });
  4. x.done(function () { console.log('done 2'); });
  5. x.always(function () { console.log('always 2'); });

  6. x.resolve();

I get the following output:

done 1
always 1
done 2
always 2

Is this a bug? Why don't all of the 'done' functions fire before the 'always' functions?  Why are they intermingled?

Thanks!