Bug Tracker

Opened 6 years ago

Closed 6 years ago

#12687 closed bug (invalid)

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:


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.resolve("sample data");


With 1.8.2. done2 callback is called with undefined.

Change History (4)

comment:1 Changed 6 years ago by dmethvin

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.

comment:2 Changed 6 years ago by danbrown

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.

comment:3 Changed 6 years ago by dmethvin

Owner: set to anonymous
Status: newpending

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

comment:4 Changed 6 years ago by trac-o-bot

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!

Note: See TracTickets for help on using tickets.