Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#9959 closed bug (invalid)

$.fn.unbind("eventtype", null) unbinds all handlers with type "eventtype"

Reported by: [email protected] Owned by: [email protected]
Priority: low Milestone: None
Component: event Version: 1.6.2
Keywords: Cc:
Blocked by: Blocking:


jQuery.event.remove currently unbinds all handlers matching the event type and namespace if ( !handler ). This means that if null is accidentally passed in, all matching handlers will be unbound.

There should be a distinction between the handler argument being absent (using arguments.length or typeof handler === "undefined") and the handler argument not being a function. If the argument is absent, the intention is to unbind all matching events. If the handler argument is present but not a function, nothing should be done (as if nothing matched its guid).

Change History (6)

comment:1 Changed 12 years ago by danheberden

I'm confused at the use-case for this. Why would anyone "accidentally" pass in null? If nothing is to be unbound, the function should not be called, ya? Plus if i'm after a boolean option to unbind, i'd rather is be falsy instead of someVar ? undefined : null;

comment:2 Changed 12 years ago by dmethvin

Why are you calling jQuery.event.remove directly anyway? It is not a public API. And if you passed in null it sounds like you have a code error, like danheberden said.

comment:3 Changed 12 years ago by dmethvin

Owner: set to [email protected]
Status: newpending

comment:4 Changed 12 years ago by [email protected]

Status: pendingnew

Hmm, maybe the fix should be on unbind rather than on remove. Yes, passing in null is probably a code error. But when null is passed as a handler to .bind(), it's handled gracefully (without throwing an exception). For unbinding, I think handling that case gracefully would mean to not unbind all unrelated handlers.

comment:5 Changed 12 years ago by Rick Waldron

Component: unfiledevent
Priority: undecidedlow
Resolution: invalid
Status: newclosed

I'm not sure why we're even debating this. Passing null as a second arg to unbind is incorrect. The second arg has accepted params: handler or false;

comment:6 Changed 12 years ago by dmethvin

Given the reply, I agree this is invalid.

But when null is passed as a handler to .bind(), it's handled gracefully (without throwing an exception).

That is not documented behavior, I wouldn't depend on it to work that way forever.

Note: See TracTickets for help on using tickets.