Most of the functions in the Promise interface fall into little groups, arranged along a few small dimensions. Those dimensions are:
- Type of value contained in the promise (scalar, array, or object), or of its properties (function or not).
- Side effects like mutation vs. pure functions
- Success callback vs. error callback
This would be fun to graph, but in English:
thencalls the given function with the value of the promise as its first argument (unless the promise has already been rejected).
thenfor arrays. It applies the given function to every item in the array, and returns a new array with the function’s return value for that item, in the same order.
map: side effects for arrays. The original array is returned (plus any mutation you may have applied to its members).
then: side effects for scalar values.
thenbut for promises that have been rejected (which means some earlier step in the promise chain raised an error).
tapCatchis a combination of
catch(operate on rejected promises) and
tap(for side effect).
gettakes a string (or number in the case of arrays) and returns the promise’s value’s property with that name.
get, but for properties that are functions. You can also pass arguments to the called function.
allis for when the value of the promise is an array containing more promises. It returns only once all of those promises have resolved.
allfor when the value of the promise is an object (or Map), and its properties are promises.