Skip to main content

Bug Tracker

Side navigation

#12253 closed bug (worksforme)

Opened August 10, 2012 07:49PM UTC

Closed August 13, 2012 04:49PM UTC

Last modified August 14, 2012 01:40PM UTC

notifyWith isn't working with $.when

Reported by: nticompass@gmail.com 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)

Attachments (0)
Change History (5)

Changed August 10, 2012 08:02PM UTC by tentonaxe comment:1

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/

Changed August 13, 2012 04:49PM UTC by jaubourg comment:2

_comment0: 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/ 1344876567235599
resolution: → worksforme
status: newclosed

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/

Changed August 13, 2012 07:55PM UTC by nticompass@gmail.com comment:3

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

Changed August 13, 2012 08:25PM UTC by jaubourg comment:4

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.

Changed August 14, 2012 01:40PM UTC by nticompass@gmail.com comment:5

Replying to [comment:4 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?"