Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All Event Bindings Should be Namespaced #505

Closed
ProLoser opened this issue Feb 25, 2012 · 3 comments
Closed

All Event Bindings Should be Namespaced #505

ProLoser opened this issue Feb 25, 2012 · 3 comments

Comments

@ProLoser
Copy link

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.

This was referenced Jul 24, 2013
@pfiller
Copy link
Contributor

pfiller commented Jul 24, 2013

Thanks @ProLoser. All event bindings in the jQuery version of Chosen are now namespaced appropriately.

@pfiller pfiller closed this as completed Jul 24, 2013
@koenpunt
Copy link
Collaborator

Keep in mind that this is not merged yet.

@pfiller
Copy link
Contributor

pfiller commented Jul 24, 2013

Oh! You're totally right. I have too many dang tabs open.

The PR is #1396 and it should land soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants