]> source.dussan.org Git - jquery.git/commitdiff
Fixes #9446. Context is properly propagated using pipe. If context was the original...
authorjaubourg <j@ubourg.net>
Thu, 30 Jun 2011 23:51:50 +0000 (01:51 +0200)
committerjaubourg <j@ubourg.net>
Thu, 30 Jun 2011 23:51:50 +0000 (01:51 +0200)
src/deferred.js
test/unit/deferred.js

index 5cc5fb5be951dfbf346637b8b13fa6da9ff67cf9..e543f151825933388d51826f1a1b0bcbfab35057 100644 (file)
@@ -122,7 +122,7 @@ jQuery.extend({
                                                                if ( returned && jQuery.isFunction( returned.promise ) ) {
                                                                        returned.promise().then( newDefer.resolve, newDefer.reject );
                                                                } else {
-                                                                       newDefer[ action ]( returned );
+                                                                       newDefer[ action + "With" ]( this === deferred ? newDefer : this, [ returned ] );
                                                                }
                                                        });
                                                } else {
index 89c9c612d931b1f966bade3e22df28d41243f7d0..fbe2907078df69e59f54b5d895f54ca12c715815 100644 (file)
@@ -275,6 +275,33 @@ test( "jQuery.Deferred.pipe - deferred (fail)", function() {
        strictEqual( value3, 6, "result of filter ok" );
 });
 
+test( "jQuery.Deferred.pipe - context", function() {
+
+       expect(4);
+
+       var context = {};
+
+       jQuery.Deferred().resolveWith( context, [ 2 ] ).pipe(function( value ) {
+               return value * 3;
+       }).done(function( value ) {
+               strictEqual( this, context, "custom context correctly propagated" );
+               strictEqual( value, 6, "proper value received" );
+       });
+
+       var defer = jQuery.Deferred(),
+               piped = defer.pipe(function( value ) {
+                       return value * 3;
+               });
+
+       defer.resolve( 2 );
+
+       piped.done(function( value ) {
+               strictEqual( this.promise(), piped, "default context gets updated to latest defer in the chain" );
+               strictEqual( value, 6, "proper value received" );
+       });
+});
+
+
 test( "jQuery.when" , function() {
 
        expect( 23 );