Commit 23d7cf04 authored by jaubourg's avatar jaubourg

Deferred: .resolve(), .reject() and .notify() now set the callback context to...

Deferred: .resolve(), .reject() and .notify() now set the callback context to the promise instance rather than the deferred instance ; .then() has also been amended. Fixes #11405.
parent 282c044d
...@@ -32,7 +32,7 @@ jQuery.extend({ ...@@ -32,7 +32,7 @@ jQuery.extend({
.fail( newDefer.reject ) .fail( newDefer.reject )
.progress( newDefer.notify ); .progress( newDefer.notify );
} else { } else {
newDefer[ action + "With" ]( this === deferred ? newDefer : this, [ returned ] ); newDefer[ action + "With" ]( this === promise ? newDefer.promise() : this, [ returned ] );
} }
} : } :
newDefer[ action ] newDefer[ action ]
...@@ -70,8 +70,11 @@ jQuery.extend({ ...@@ -70,8 +70,11 @@ jQuery.extend({
}, tuples[ i ^ 1 ][ 2 ].disable, tuples[ 2 ][ 2 ].lock ); }, tuples[ i ^ 1 ][ 2 ].disable, tuples[ 2 ][ 2 ].lock );
} }
// deferred[ resolve | reject | notify ] = list.fire // deferred[ resolve | reject | notify ]
deferred[ tuple[0] ] = list.fire; deferred[ tuple[0] ] = function() {
deferred[ tuple[0] + "With" ]( promise, arguments );
return this;
};
deferred[ tuple[0] + "With" ] = list.fireWith; deferred[ tuple[0] + "With" ] = list.fireWith;
}); });
......
...@@ -292,7 +292,7 @@ test( "jQuery.Deferred.then - context", function() { ...@@ -292,7 +292,7 @@ test( "jQuery.Deferred.then - context", function() {
defer.resolve( 2 ); defer.resolve( 2 );
piped.done(function( value ) { piped.done(function( value ) {
strictEqual( this.promise(), piped, "default context gets updated to latest defer in the chain" ); strictEqual( this, piped, "default context gets updated to latest promise in the chain" );
strictEqual( value, 6, "proper value received" ); strictEqual( value, 6, "proper value received" );
}); });
}); });
...@@ -395,8 +395,8 @@ test( "jQuery.when - joined", function() { ...@@ -395,8 +395,8 @@ test( "jQuery.when - joined", function() {
expected = shouldResolve ? [ 1, 1 ] : [ 0, undefined ], expected = shouldResolve ? [ 1, 1 ] : [ 0, undefined ],
expectedNotify = shouldNotify && [ willNotify[ id1 ], willNotify[ id2 ] ], expectedNotify = shouldNotify && [ willNotify[ id1 ], willNotify[ id2 ] ],
code = id1 + "/" + id2, code = id1 + "/" + id2,
context1 = defer1 && jQuery.isFunction( defer1.promise ) ? defer1 : undefined, context1 = defer1 && jQuery.isFunction( defer1.promise ) ? defer1.promise() : undefined,
context2 = defer2 && jQuery.isFunction( defer2.promise ) ? defer2 : undefined; context2 = defer2 && jQuery.isFunction( defer2.promise ) ? defer2.promise() : undefined;
jQuery.when( defer1, defer2 ).done(function( a, b ) { jQuery.when( defer1, defer2 ).done(function( a, b ) {
if ( shouldResolve ) { if ( shouldResolve ) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment