Bug Tracker

Opened 9 years ago

Closed 9 years ago

#7852 closed bug (wontfix)

Problem of Adding same Event listener Hanlder

Reported by: anonymous Owned by:
Priority: undecided Milestone: 1.6
Component: unfiled Version: 1.4.2
Keywords: Cc:
Blocked by: Blocking:

Description

jQuery 1.4.2 line 1663-1664:

      // Add the function to the element's handler list
      handlers.push( handleObj );

to

      // Add the function to the element's handler list
      var handle_exists = false;
      for (var i = 0; i < handlers.length; ++i) {
        if (handlers[i].guid == handleObj.guid) {
          handle_exists = true;
        }
      }
      if (handle_exists == false) {
        handlers.push( handleObj );
      }

I guess, This jQuery(>=1.4.2)'s problem is caused by changing type of handlers object to array, line 1639.

Change History (2)

comment:1 Changed 9 years ago by anonymous

The reason to post is I want to use jquery.hotkey.js with lastest jQuery. But I faced the problem with jQuery over 1.4.2 version.

sample problem code:

<!DOCTYPE html>
<html>
  <head>
    <script src="./jquery-1.4.2.js"></script>
    <script src="./jquery.hotkeys-0.7.9.js"></script>
    <script>
      $(function() {
        function output() { console.log(this); }
        $(document.body).bind('keydown', 'j', output);
        $(document.body).bind('keydown', 'k', output);
      });
    </script>
  </head>
  <body></body>
</html>

Opening this and pressing 'j' or 'k', JS console gets document.body three times. To suspend code to the last post one, JS console gets once.

comment:2 Changed 9 years ago by snover

Resolution: wontfix
Status: newclosed

This is, unfortunately, intentional. The same handler can be bound multiple times with different eventData.

Note: See TracTickets for help on using tickets.