sudhirj/simply-deferred — pull request #14 by rraval (2013-07-19 03:25:37+00:00)
Title: Better jQuery Compatibility

A small set of patches to nudge this library closer to jQuery's behaviour.

Probably the biggest change involves the special casing `$.when()` does when handling child deferreds that are resolved with single or no arguments. jQuery promotes those resolutions to the top level (instead of passing along a unary or empty list of arguments). It looks like #8 was an attempt at solving this very issue, but ended up special casing calls to `$.when()` with only a single deferred, which is only a partial solution. This change very likely breaks backwards compatibility.

The other changes are rather minor and serve as more of a convenience. They are all legal in jQuery, but not in simply-deferred:

- `.promise()` can be called on promises. In jQuery, `$.when().promise().promise()` is entirely valid, and returns the first promise.
- `$.when()` can handle non-deferred arguments, and treats them as pre-resolved deferreds. This turns out making `$.when(...)` with all resolved arguments a shorthand for `$.Deferred().resolve(...).promise()`.
- jQuery treats every object that implements a `.promise()` function as a deferred. This has special implications for `.pipe()`.