Add catch to promise objects #2102

Closed
tracker1 opened this Issue Feb 19, 2015 · 5 comments

Projects

None yet

6 participants

@tracker1

This relates to #1722 but a far simpler request... given that the .then method matches the Promise spec (with the extra progress parameter), it would be nice that there be a compatible .catch method... (per @dmethvin) this could call and return .then(null,fn) as a passthrough.

@dmethvin
Member

I can see us creating .catch(fn) as an alias for .then(null, fn). That is different than .done(fn) though because the latter adds a new handler to the existing Deferred.

@markelog markelog added the Deferred label Feb 19, 2015
@tracker1

of course, this would need to be done with ['catch'] so as not to trigger reserved word treatment in older browsers.

@dcherman
Contributor
dcherman commented Mar 2, 2015

Giant +1 on this. Since these Promises aren't based on a prototype, it's much easier for this to be supported internally rather than having to do something like wrap the constructor and decorate the returned promise.

@gibson042 gibson042 changed the title from Alias .catch alias to Deferred's .fail handler. to Add catch to promise objects Apr 22, 2015
@gibson042 gibson042 added this to the 3.0.0 milestone Apr 22, 2015
@gibson042 gibson042 self-assigned this Apr 22, 2015
@gibson042
Member

I updated the title for accuracy. Suggested implementation:

"catch": function( fn ) {
    return promise.then( null, fn );
}
@markelog
Member

Sounds like a blocker to me

@timmywil timmywil added the Blocker label Apr 23, 2015
@timmywil timmywil added a commit to timmywil/jquery that referenced this issue Jul 6, 2015
@timmywil timmywil Deferred: add .catch handler
Fixes gh-2102
9827085
@timmywil timmywil added a commit to timmywil/jquery that referenced this issue Jul 6, 2015
@timmywil timmywil Deferred: add .catch handler
Fixes gh-2102
84ccf26
@timmywil timmywil added a commit that referenced this issue Jul 6, 2015
@timmywil timmywil Deferred: add .catch handler
Fixes gh-2102
ef77f83
@timmywil timmywil closed this in #2451 Jul 6, 2015
This was referenced Nov 16, 2015
@sqrthree sqrthree referenced this issue in sqrthree/sqrthree.github.io Feb 20, 2016
Open

【译】jQuery 3.0 以及兼容版的 Alpha 版本发布 #3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment