On Sep 8, 2009, at 9:42 AM, KeeganWatkins wrote: > @Oleg - > >>> Your way is not shorter as this one > > It isn't simply about brevity, although that is a concern. My main > goal is to increase the use cases that these methods are able to > account for. In your "as-basic-as-possible" example, it's true that > simply chaining calls to the shorthand methods, i.e. click(), > mouseover > (), mouseout() could save a few lines, but ultimately that is trivial. > Also, how would you unbind those handlers if you needed to ("I don't > ever need to" is not really a good enough answer) ? By passing > anonymous functions to bind(), you've lost your ability to clean up > after yourself. I don't really want to get into a debate over personal > coding style, but the fact remains that there are going to be > situations where a group of bound handlers needs to be unbound. So, > for your example, we have to change the actual handlers to named > function references. Then, assuming we have named functions to work > with, your "shorter" answer requires that we again chain the calls to > unbind() (one each per handler). So, your "shorter" solution isn't > shorter unless you give up using unbind(), which is not an option in > my case.
Hi Keegan, Without getting into the merits of your proposal as a whole, I think you're mistaken about the inability to "clean up after yourself" when passing anonymous functions to bind. This is what namespaced events are for. If you change Oleg's example just a bit ... $("#myID").bind('click.mynamespace', function(e) { // handle click }) .bind('mouseover.mynamespace', function(e) { // handle mouseover }) .bind('mouseout.mynamespace', function(e) { // handle mouseout }); ... you can unbind this click handler without unbinding other click handlers by doing this: $("#myID").unbind('click.mynamespace'); You can also unbind all of those handlers that have the .mynamespace namespace by doing this: $("#myID").unbind('.mynamespace'); Even without the namespaces, we don't need to "chain the calls to unbind()," since both bind and unbind can take space-delimited events as the first argument: $("#myID").unbind('click mouseover mouseout'); --Karl --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@googlegroups.com To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~----------~----~----~----~------~----~------~--~---