Bug Tracker

Modify

Ticket #7651 (closed bug: duplicate)

Opened 2 years ago

Last modified 2 years ago

bind() and trigger() fail on plain javascript objects if a method “handle” exists

Reported by: rs@… Owned by:
Priority: blocker Milestone: 1.5
Component: event Version: 1.4.4
Keywords: regression Cc:
Blocking: Blocked by:

Description

This is a regression from the changes made in 1.4.3. The following works fine:

var a = {};
jQuery(a).bind("myEvent", function() {
    jQuery('body').text("Gaga");
});
jQuery(a).trigger('myEvent');

Whereas this does not work:

var a = {};
a.handle = function(){};
jQuery(a).bind("myEvent", function() {
    jQuery('body').text("Gaga");
});
jQuery(a).trigger('myEvent');

Change History

comment:1 Changed 2 years ago by anonymous

Both variants work fine in jQuery 1.4.2. Test case is at  http://www.jsfiddle.net/ZtKLD/

comment:2 Changed 2 years ago by snover

  • Keywords regression added
  • Priority changed from undecided to blocker
  • Status changed from new to open
  • Milestone changed from 1.next to 1.5

comment:3 Changed 2 years ago by snover

  • Component changed from unfiled to event

comment:4 follow-up: ↓ 5 Changed 2 years ago by rwaldron

Could this possibly be related to #7500 ?

comment:5 in reply to: ↑ 4 Changed 2 years ago by jitter

Replying to rwaldron:

Could this possibly be related to #7500 ?

I don't think so. This probably comes from the changes in 1.4.3 to the data() method, as we now are storing the data() data on plain js objects directly.

Now the events add() method seem to get confused  here and  here as elemData.handle is now set when there is a "handle" property on the js object. Which of course it wasn't in 1.4.2 where data() returned nothing on a plain js object unless there was already data associated with it in the internal cache. But in 1.4.2 a similar bug existed the other way around

 http://jsfiddle.net/jitter/zPz7j/

So the main issue is we really shouldn't be storing a property named handle directly on a js object.

comment:6 Changed 2 years ago by rwaldron

  • Status changed from open to closed
  • Resolution set to duplicate

comment:7 Changed 2 years ago by rwaldron

Duplicate of #6968.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.