harvesthq/chosen — Issue #505: All Event Bindings Should be Namespaced
Author: ProLoser
Created: 2012-02-25 01:16:41+00:00
State: open

In jQuery, when you bind use `click()` or `focus()`, you bind to the general purpose event. However, if you use the `bind()` function, you can specify a namespace for the event, such as `bind('click.chosen')`. This event will still be triggered by regular `click` events or even specific ones (like trigger('click.chosen') without triggering other namespaced events).

The purpose of doing this is so that when you UNBIND, you do not unbind everyone else's callbacks. Most of the time this isn't a big deal, but if the app dev or a third party wants to bind events to the same elements as you, or if you bind onto global events (such as $(document).click(), which IS done for hiding) then when you go and UNBIND the general click events you will be unbinding everyone elses callbacks. Instead, pass the namespace to unbind and you will prevent breaking anyone else's code.

This should be a mandatory standard for all jQuery plugins, but unfortunately I think few people actually know about it. It's causing issues for me in some of my code and most of the event binds are abstracted and hard to find for me to refactor.