Bug Tracker

Modify

Ticket #9278 (closed bug: wontfix)

Opened 3 years ago

Last modified 2 years ago

unbind is too greedy when unbinding proxy functions

Reported by: sahab.yazdani+jquery@… Owned by: rwaldron
Priority: undecided Milestone: 1.next
Component: event Version: 1.6.1
Keywords: Cc:
Blocking: Blocked by:

Description

Steps to reproduce:

  1. Create two proxies of the same function but using different contexts.
  2. Bind these two proxies unto the same event handler using $().bind
  3. Unbind one of the proxies using the proxied function handle
  4. Trigger the event

Actual Result:

Note that no event gets triggered

Expected Result:

The version of the handler that was not unbound should get triggered.

The JSFiddle will clarify this:  http://jsfiddle.net/RD7ZF/7/

As far as I can tell, jQuery has worked like this from the dawn of time, but to me the behviour is rather unexpected. Because the contexts for the proxy functions are different, by extension the two proxy methods are different whereas unbind treats them as being the same.

Change History

comment:1 Changed 3 years ago by rwaldron

  • Owner set to rwaldron
  • Status changed from new to assigned
  • Component changed from unfiled to event

Confirmed.

comment:2 Changed 3 years ago by ajpiano

  • Status changed from assigned to closed
  • Resolution set to wontfix

Thanks for your time and interest in helping the jQuery project, but this is by design and we do not intend to change this functionality, as it would greatly increase the complexity of creation and subsequent unbinding of proxied functions.

comment:3 Changed 3 years ago by dmethvin

  • Keywords needsdocs added

This is something worth documenting at least; heavy users of jQuery.proxy may not expect the behavior. However, many jQuery.proxy users will be using delegated events anyway and be less likely to need to unbind perhaps?

comment:4 Changed 3 years ago by dmethvin

  • Keywords needsdocs removed

Added a paragraph to describe this behavior and recommended event namespaces as the solution.

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.