- object = object && jQuery.isFunction( object.promise ) ?
- object :
- jQuery.Deferred().resolve( object );
- return object.promise();
+ var lastIndex = arguments.length,
+ deferred = lastIndex <= 1 && object && jQuery.isFunction( object.promise ) ?
+ object :
+ jQuery.Deferred(),
+ promise = deferred.promise();
+
+ if ( lastIndex > 1 ) {
+ var array = slice.call( arguments, 0 ),
+ count = lastIndex,
+ iCallback = function( index ) {
+ return function( value ) {
+ array[ index ] = arguments.length > 1 ? slice.call( arguments, 0 ) : value;
+ if ( !( --count ) ) {
+ deferred.resolveWith( promise, array );
+ }
+ };
+ };
+ while( ( lastIndex-- ) ) {
+ object = array[ lastIndex ];
+ if ( object && jQuery.isFunction( object.promise ) ) {
+ object.promise().then( iCallback(lastIndex), deferred.reject );
+ } else {
+ --count;
+ }
+ }
+ if ( !count ) {
+ deferred.resolveWith( promise, array );
+ }
+ } else if ( deferred !== object ) {
+ deferred.resolve( object );
+ }
+ return promise;