#10307 closed enhancement (duplicate)
$.when should accept array of deferreds
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | low | Milestone: | None |
Component: | deferred | Version: | 1.6.4 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
$.when should accept array of deferreds as parameter. currently, it accepts just 1 deferred object or more arguments (more deferreds separated by comma)
Change History (6)
comment:1 Changed 12 years ago by
Component: | unfiled → deferred |
---|---|
Priority: | undecided → low |
Resolution: | → duplicate |
Status: | new → closed |
comment:2 Changed 12 years ago by
comment:5 Changed 12 years ago by
We don't intend to add this because the values that are passed to jQuery.when are not required to be observable - an array, like anything else besides a deferred or promise, is treated as something that has already been resolved. Another option like introspecting an array to check for the existence of deferreds is overly invasive and brittle, so I believe we'll continue to recommend using $.when.apply(null, arrayOfDeferreds). If you like, you can duckpunch it into your jQuery with something like
var oldWhen = jQuery.when; jQuery.when = function( arg ) { if ( jQuery.isArray( arg ) ) { return oldWhen.apply( null, arg ); } else { return oldWhen.apply( Array.prototype.slice.call( arguments ) ); } };
comment:6 Changed 10 years ago by
Not having a way to wait for an array of promises in jQuery is a huge drawback IMHO. In all the time I used $.when in almost all of them I have to use the apply invocation.
Only in the simplest of cases you will store your jqXHR in variables, because doing it that way does not scale for more than 3 or 4 instances and makes for hard to maintian/evolve code.
Both https://github.com/kriskowal/q https://github.com/cujojs/when and https://github.com/kriszyp/node-promise support that syntax, and it is hard for me to see why jQuery does not.
Duplicate of #8256.