Skip to content

Instantly share code, notes, and snippets.

@asakusuma
Last active August 29, 2015 14:01
Show Gist options
  • Save asakusuma/7498a5aba85e1274e176 to your computer and use it in GitHub Desktop.
Save asakusuma/7498a5aba85e1274e176 to your computer and use it in GitHub Desktop.

A+ Promises vs. jQuery.defer

thisPromiseRejects.then(fulfillHandler1)
  .then(fulfillHandler2, rejectHandler2);

###jQuery rejectionHandler1 and rejectionHandler2 will be called.

###A+ rejectionHandler1 and rejectionHandler2 will be called.

thisPromiseRejects.then(fulfillHandler1, rejectHandler1)
  .then(fulfillHandler2, rejectHandler2);

###jQuery rejectionHandler1 and rejectionHandler2 will be called.

###A+ Assuming rejectHandler1 does not throw an error, rejectHandler1 and fulfillHandler2 will be called.

Spec

then must return a promise [3.3].

promise2 = promise1.then(onFulfilled, onRejected);
  1. If either onFulfilled or onRejected returns a value x, run the Promise Resolution Procedure [[Resolve]](promise2, x).
  2. If either onFulfilled or onRejected throws an exception e, promise2 must be rejected with e as the reason.
  3. If onFulfilled is not a function and promise1 is fulfilled, promise2 must be fulfilled with the same value as promise1.
  4. If onRejected is not a function and promise1 is rejected, promise2 must be rejected with the same reason as promise1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment