views:

376

answers:

2

I just wanted to get the general consensus on which is a better mode of event delegation in JS between bubbling and capturing.

Now I understand that depending on a particular use-case, one might want to use capturing phase over bubbling or vice versa but I want to understand what delegation mode is preferred for most general cases and why (to me it seems bubbling mode).

Or to put it in other words, is there a reason behind W3C addEventListener implementation to favor the bubbling mode. [capturing is initiated only when you specify the 3rd parameter and its true. However, you can forget that 3rd param and bubbling mode is kicked in]

I looked up the JQuery's bind function to get an answer to my question and it seems it doesn't even support events in capture phase (it seems to me because of IE not support capturing mode).

So looks like bubbling mode is the default choice but why?

A: 

I'm not certain but I'm pretty sure that anything you can do with bubbling you can do with capturing and vice versa.

The idea that you'd have some events bubbling and some capturing in the same app sounds like a good way to make things very confusing. What I'm saying is, I don't think bubbling versus capturing really matters. What matters is that you pick one and stick with it.

W3C's APIs often contain this sort of thing where they have a lot of features that nobody really cares about. Perhaps this is another example of how good defaults can remove the need for configuration or even whole features.

Ollie Saunders
Focus/blur events don't bubble, but can be delegated at a higher level during the capture phase - http://www.quirksmode.org/blog/archives/2008/04/delegating_the.html
El Yobo
A: 

In the past it was a platform issue, Internet Explorer had a bubbling model, and Netscape was more about capturing (yet supported both).

The W3C model calls for you be able to choose which one you want.

I think bubbling is more popular because, as stated there are some platforms that only support bubbling...and it sort of makes sense as a "default" mode.

Which one you choose is largely a product of what you are doing and what makes sense to you.

MisterMister
because of IE, bubbling seems to be the default choice.here is what I found on prototype.js website"Prior to Prototype 1.6, Event.observe supported a fourth argument (useCapture), a boolean that indicated whether to use the browser's capturing phase or its bubbling phase. Since MSIE does not support the capturing phase, we removed this argument from 1.6, lest it give users the false impression that they can use the capturing phase in all browsers." [http://api.prototypejs.org/dom/event/observe/]
Rajat