Side navigation
#8596 closed bug (invalid)
Opened March 22, 2011 11:02PM UTC
Closed March 23, 2011 12:06AM UTC
Last modified March 23, 2011 06:45PM UTC
Event $(this).bind conflict with $(this).trigger
Reported by: | eswigert@decipherinc.com | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | 1.next |
Component: | event | Version: | 1.5.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
There seems to be a conflict when trying to trigger an event that has the same name as a function in a custom javascript object. Example:
var Class = {
construct: function() {
$("body").bind("click", $.proxy(this, "onBodyClick"));
},
onBodyClick: function(e) {
$(this).trigger("onBodyClick");
}
}
The above code will create a loop and the "onBodyClick" function will run over and over again. Not sure what this has to do with, but I've been creating a pretty decent sized application powered by jquery and this error has caught me a few times.
Attachments (0)
Change History (3)
Changed March 22, 2011 11:23PM UTC by comment:1
Changed March 23, 2011 12:06AM UTC by comment:2
component: | unfiled → event |
---|---|
resolution: | → invalid |
status: | new → closed |
The problem is not jQuery, but that you have misunderstood how you're passing context with the $.proxy call. When I look at your code and I see the result in the console, that's exactly what I expect to see.
Changed March 23, 2011 06:45PM UTC by comment:3
Really? I can accept that. Could you explain why it's happening that way? I thought I was triggering an event, but it seems like it's actually calling a function with that name (and triggering the event). If it's a scope issue with the proxy can you help me understand what is going on there?
Thanks.
Here is the link to the jsfiddle example.
http://jsfiddle.net/earl3s/zLeYa/