RE: [Future] First arguments should not be optional

From: Jonas Sicking [jonas@sicking.cc]

> On Wed, May 8, 2013 at 11:02 AM, Domenic Denicola <domenic@domenicdenicola.com> wrote:
>> Finally, I think the correct behavior is to ignore non-Callables, instead of throwing.

> Out of curiosity, why do you prefer that behavior? As an author I would feel that it's pretty hostile for an API to simply ignore what I requested, rather than letting me know through a thrown exception.

It's just more lenient, aligning better with existing JS libraries I've seen (not just promise ones). The spec evidence is pretty sparse---`Array.prototype.sort` versus `JSON.stringify` and `JSON.parse`. But in my experience most libraries will do either a `typeof x === "function"` test or a `if (x)` test before usage; none will do `if (typeof x !== "function" && typeof x !== "undefined")` test.

As a concrete example of how this is useful, consider

```js
var onFulfilled = handlers && handlers.onFulfilled;
promise.then(onFulfilled).done();
```

If `handlers` is `null` then this will break if only `undefined` is accepted; instead you must do

```js
var onFulfilled = handlers ? handlers.onFulfilled : undefined;
```

It's a pretty minor point though, all said. Allowing only `undefined` is fine too.

Received on Wednesday, 8 May 2013 19:58:41 UTC