Skip to main content

Bug Tracker

Side navigation

#12687 closed bug (invalid)

Opened October 09, 2012 01:07PM UTC

Closed October 24, 2012 08:51AM UTC

promise.then callback data is not properly resolved

Reported by: anonymous Owned by: anonymous
Priority: undecided Milestone: None
Component: unfiled Version: 1.8.2
Keywords: Cc:
Blocked by: Blocking:
Description

I have this code executed in 1.7.1 as resovle ''args'' parameter was properly passed to both done1 and done2 callbacks

(function () {

var deferred = $.Deferred();

var done1 = function (data) {

};

var done2 = function (data) {

};

deferred.then(done1).then(done2);

deferred.resolve("sample data");

})();

With 1.8.2. done2 callback is called with ''undefined''.

Attachments (0)
Change History (4)

Changed October 09, 2012 01:11PM UTC by dmethvin comment:1

In jQuery 1.8, the .then() method creates a new promise rather than adding a callback to the existing promise. This provides better interoperability with other Promise/A implementations. To get the old behavior, use deferred.done(done1).done(done2);

Although this was mentioned in the blog notes the docs do need to be updated.

Changed October 09, 2012 08:53PM UTC by danbrown comment:2

Whether or not it creates a new promise object, this behavior is still incorrect. The callbacks that are attached should be called with the arguments of resolve(), regardless of which promise object they were attached to. This is a bug.

The same incorrect behavior is produced by the promise object returned by Deferred.then().

Deferred.promise() returns a promise object that exhibits correct behavior.

This code snippet also shows the behavior in the console:

var x = new $.Deferred();

x.then(function(res){console.log(res);}).then(function(res){console.log(res);});

x.resolve([1,2]);

[1,2] should be logged to the console twice, but instead it is logged once and then undefined is logged.

Changed October 09, 2012 10:18PM UTC by dmethvin comment:3

owner: → anonymous
status: newpending

Does this clarify things for you? http://jsfiddle.net/4TVLq/

Changed October 24, 2012 08:51AM UTC by trac-o-bot comment:4

resolution: → invalid
status: pendingclosed

Because we get so many tickets, we often need to return them to the initial reporter for more information. If that person does not reply within 14 days, the ticket will automatically be closed, and that has happened in this case. If you still are interested in pursuing this issue, feel free to add a comment with the requested information and we will be happy to reopen the ticket if it is still valid. Thanks!