Skip to main content

Bug Tracker

Side navigation

#8791 closed bug (invalid)

Opened April 06, 2011 08:25PM UTC

Closed April 07, 2011 12:51AM UTC

Event data being overwritten

Reported by: davestein Owned by:
Priority: undecided Milestone:
Component: event Version: 1.5.1
Keywords: Cc:
Blocked by: Blocking:

If I have two binds of the same type to the same element, with different object data, future callbacks have data from the wrong bind.

jsfiddle doesn't have 1.5.2 yet so I tested officially on 1.5.1 and I don't see a fix for this in changelog in 1.5.2.

Attachments (0)
Change History (10)

Changed April 06, 2011 08:36PM UTC by scottgonzalez comment:1

I'm not sure this can be considered a bug, but I'm interested to see what happens with this for two reasons. It's related to my request for a single event object to be used all the time (which was determined not to be feasible) and it's delaying use of an event (which isn't fully supported - #7278).

Changed April 06, 2011 08:37PM UTC by rwaldron comment:2

component: unfiledevent
resolution: → worksforme
status: newclosed

Changed April 06, 2011 08:39PM UTC by rwaldron comment:3

@scott.gonzalez What about this: ?

Changed April 06, 2011 08:44PM UTC by anonymous comment:4

Just loaded 1.5.2 on my site and am still experiencing. I'll keep checking for Fiddle to update the versions to go there too.

The settimeout in my fiddle is simulating that I have local functions inside the one that grabs e. I don't need to reference e again until another click later on.

Changed April 06, 2011 08:47PM UTC by DaveStein comment:5

I don't understand why it's closed and working for you. The example in your fiddle is very different than mine. I can write another more complicated fiddle, without using setTimeout, that will show the error.

( Didn't mean to post as anon last time. Can't remember my login and forgot password isn't ending up in my mail. )

Changed April 06, 2011 08:54PM UTC by DaveStein comment:6 Here is my fiddle that doesn't use setTimeout yet there is still an issue.

And as Scott points out the event is NOT being lost, just the property of data :

It's weird that everything stays but that becomes undefined.

Changed April 06, 2011 09:07PM UTC by scottgonzalez comment:7

Think about it this way: Events are just objects. If you pass the same object to several functions, any of those functions can modify properties on that object. If one of those functions happens to hold on to a reference to that object, that won't prevent other functions from modifying its properties. That's exactly what's happening here. There's nothing special about the data property. jQuery can potentially change it on every handler invocation. If you care about the data being "protected" you should put it in a closure and bind your event handler in the same closure.

Changed April 06, 2011 10:37PM UTC by DaveStein comment:8

Okay after digging through how everything is done in the jQuery source, I see how it's not a bug and impossible to do what I was suggesting.

Sorry for the trouble.

Changed April 07, 2011 12:48AM UTC by dmethvin comment:9

resolution: worksforme
status: closedreopened

Changed April 07, 2011 12:51AM UTC by dmethvin comment:10

resolution: → invalid
status: reopenedclosed

For accounting purposes I'm going to close this as invalid. It's not okay to use the Event object past an event handler's lifetime for reason #7278 among others.