Opened 12 years ago
Closed 12 years ago
#8791 closed bug (invalid)
Event data being overwritten
Reported by: | davestein | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | 1.next |
Component: | event | Version: | 1.5.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
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.
Change History (10)
comment:1 Changed 12 years ago by
comment:2 Changed 12 years ago by
Component: | unfiled → event |
---|---|
Resolution: | → worksforme |
Status: | new → closed |
Works for me.
One handler: http://jsfiddle.net/rwaldron/PsSNG/ Two handlers: http://jsfiddle.net/rwaldron/PsSNG/6/
comment:3 Changed 12 years ago by
@scott.gonzalez What about this: https://github.com/jquery/jquery/pull/301 ?
comment:4 Changed 12 years ago by
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.
comment:5 Changed 12 years ago by
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. )
comment:6 Changed 12 years ago by
http://jsfiddle.net/davestein/q9Rjq/10/ 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 : http://jsfiddle.net/q9Rjq/9/
It's weird that everything stays but that becomes undefined.
comment:7 Changed 12 years ago by
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.
comment:8 Changed 12 years ago by
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.
comment:9 Changed 12 years ago by
Resolution: | worksforme |
---|---|
Status: | closed → reopened |
comment:10 Changed 12 years ago by
Resolution: | → invalid |
---|---|
Status: | reopened → closed |
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.
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).