Bug Tracker

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#12253 closed bug (worksforme)

notifyWith isn't working with $.when

Reported by: [email protected] 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 tentonaxe

Modifying line 1336 to use this in place of promise makes the fiddle run correctly, though I don't know what other impacts that may have.

http://jsfiddle.net/3DDSa/18/

comment:2 Changed 10 years ago by jaubourg

Resolution: worksforme
Status: newclosed

Using when, you "join" two promises. As of 1.8, you also "join" contexts. So, this in the context of you when call is an array containing both contexts. Just deference to get the one context you need: http://jsfiddle.net/3D4wq/

Version 0, edited 10 years ago by jaubourg (next)

comment:3 Changed 10 years ago by [email protected]

So, in 1.7.2, there's no way to get the context from "notifyWhen" when using "when"?

comment:4 Changed 10 years ago by jaubourg

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 in reply to:  4 Changed 10 years ago by [email protected]

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?"

Note: See TracTickets for help on using tickets.