Ticket #13160 (closed bug: fixed)
Deferred.then doesn't propagete custom context
| Reported by: | nanto_vi | Owned by: | jaubourg |
|---|---|---|---|
| Priority: | blocker | Milestone: | 1.9 |
| Component: | deferred | Version: | 1.9b1 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
jQuery 1.9b1 changed a context (value of 'this') in piped promises.
- http://jsfiddle.net/8qCkf/1/ (1.8.2)
- http://jsfiddle.net/gUgMJ/1/ (1.9.0pre)
This change affects codes that expect context to be propagated such as:
function ajaxWithRescueFrom404(settings) {
return $.ajax(settings).then(null, function (xhr, status) {
return (xhr.status === 404)
? $.Deferred().resolveWith(this, ['', status, xhr])
: this;
});
}
ajaxWithResuceFrom404({ url: ... }).done(function () {
// Treat 404 response as same as succeeded response.
// Expect that 'this' is a settings object.
});
The commit https://github.com/nanto/jquery/commit/cdac527be80fb2c6585ce6f53a83d4a9144fbf4d fixes this problem.
Change History
comment:1 Changed 4 months ago by jaubourg
- Owner set to jaubourg
- Priority changed from undecided to blocker
- Status changed from new to assigned
- Component changed from unfiled to deferred
- Milestone changed from None to 1.9
comment:2 Changed 4 months ago by nanto_vi
I made a pull request https://github.com/jquery/jquery/pull/1114
comment:3 Changed 4 months ago by nanto_vi
- Status changed from assigned to closed
- Resolution set to fixed
Propagete context of returned deferred object in Deferred.then(). Fixes #13160
Changeset: e7fdda981928befda72b78e9e2b17e33e232a603
comment:4 Changed 4 months ago by nanto
Propagate context of returned deferred object in Deferred.then(). Fixes #13160.
Changeset: 2f6b3f818fc51ee6ae44be69dc6b15b3d7a2dad4
comment:5 Changed 4 months ago by nanto
Propagate context of returned deferred object in Deferred.then(). Fixes #13160.
Changeset: 0c5d2fbabb39ef53a798535bc58690d34ea21351
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Can you make this a full-fledged pull request with unit tests to boot?