#12253 closed bug (worksforme)
notifyWith isn't working with $.when
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | undecided | Milestone: | None |
Component: | unfiled | Version: | 1.8.0 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
I noticed that when doing
$.when(a(),b()).progress(function(){ console.log(this); });
that "this" is always the promise object, even when using ".notifyWith".
Here is an example of this issue: http://jsfiddle.net/NTICompass/3DDSa/17/
(related StackOverflow question: http://stackoverflow.com/questions/11907892/notifywith-isnt-working-with-when)
Change History (5)
comment:1 Changed 10 years ago by
comment:2 Changed 10 years ago by
Resolution: | → worksforme |
---|---|
Status: | new → closed |
Using when
, you "join" two promises. As of 1.8, you also "join" contexts. So, this
in the context of your when
call is an array containing both contexts. Just deference to get the one context you need: http://jsfiddle.net/3D4wq/
comment:3 Changed 10 years ago by
So, in 1.7.2, there's no way to get the context from "notifyWhen" when using "when"?
comment:4 follow-up: 5 Changed 10 years ago by
Prior to 1.8, the context was always the new promise if one was created (using when with a single promise is a special case that returns the promise as given thus preserving callback contexts). So, yes, you'd have to use 1.8 to have access to the array of contexts.
In general, I find context handling a bit of a pain and tend to favor variables in closures whenever possible.
comment:5 Changed 10 years ago by
Replying to jaubourg:
In general, I find context handling a bit of a pain and tend to favor variables in closures whenever possible.
Agreed, I was just messing around, when I noticed "hey, why can't I do this?"
Modifying line 1336 to use
this
in place ofpromise
makes the fiddle run correctly, though I don't know what other impacts that may have.http://jsfiddle.net/3DDSa/18/