`then` is meant to return a promise, i.e. return an asynchronous value; it should never synchronously throw an error.
That said, I somewhat agree (although in JavaScript it should be `undefined`, not `null`). If we were starting clean, instead of with tons of code in the wild that did `.then(null, onRejected)` or `.then(false, onRejected)`, we would have the resulting promise be rejected with a `TypeError` if `onFulfilled` was neither `undefined` nor a function.
Re:Promises/A+
by willvarfar on Tuesday July 09, 2013 @01:13AM
(#6011227)
Hmm null is easier to pass on purpose and undefined is easier to pass by accident.
Sending in undefined for a non-trailing argument takes effort.
I think the literal null is far more communicative of the developers intent.
But the general point is, JS APIs tend to fail silently on error by design and that's something that bugs me, literally. Bugs. Lots of them.
I agree regards returning a failure rather than throwing an exception, though.
This is idiomatic JS I guess, but it bugs me to bits. IMO the parameter should be a function or it should be null; anything else should throw an error.