]> source.dussan.org Git - jquery.git/commitdiff
Eliminate redundancy of Deferred.then(). 1114/head
authornanto_vi <nanto@moon.email.ne.jp>
Mon, 7 Jan 2013 16:02:40 +0000 (01:02 +0900)
committernanto_vi <nanto@moon.email.ne.jp>
Mon, 7 Jan 2013 16:03:38 +0000 (01:03 +0900)
src/deferred.js

index 4001c2384540f22513020a4d8aeab0b944f99aea..0efc05dc3a00786990e8eb717441a84791785e9f 100644 (file)
@@ -21,24 +21,19 @@ jQuery.extend({
                                        return jQuery.Deferred(function( newDefer ) {
                                                jQuery.each( tuples, function( i, tuple ) {
                                                        var action = tuple[ 0 ],
-                                                               fn = fns[ i ];
+                                                               fn = jQuery.isFunction( fns[ i ] ) && fns[ i ];
                                                        // deferred[ done | fail | progress ] for forwarding actions to newDefer
-                                                       deferred[ tuple[1] ]( jQuery.isFunction( fn ) ?
-                                                               function() {
-                                                                       var returned = fn.apply( this, arguments );
-                                                                       if ( returned && jQuery.isFunction( returned.promise ) ) {
-                                                                               returned.promise()
-                                                                                       .done( newDefer.resolve )
-                                                                                       .fail( newDefer.reject )
-                                                                                       .progress( newDefer.notify );
-                                                                       } else {
-                                                                               newDefer[ action + "With" ]( this === promise ? newDefer.promise() : this, [ returned ] );
-                                                                       }
-                                                               } :
-                                                               function() {
-                                                                       newDefer[ action + "With" ]( this === promise ? newDefer.promise() : this, arguments );
+                                                       deferred[ tuple[1] ](function() {
+                                                               var returned = fn && fn.apply( this, arguments );
+                                                               if ( returned && jQuery.isFunction( returned.promise ) ) {
+                                                                       returned.promise()
+                                                                               .done( newDefer.resolve )
+                                                                               .fail( newDefer.reject )
+                                                                               .progress( newDefer.notify );
+                                                               } else {
+                                                                       newDefer[ action + "With" ]( this === promise ? newDefer.promise() : this, fn ? [ returned ] : arguments );
                                                                }
-                                                       );
+                                                       });
                                                });
                                                fns = null;
                                        }).promise();