what exactly the useCapture flag does?

390 views
Skip to first unread message

Darshan

unread,
May 14, 2012, 11:36:38 AM5/14/12
to General Dart Discussion
EventListenerList add(void handler(Event event), [bool useCapture])

I can't find documentation for that

Sam McCall

unread,
May 14, 2012, 12:59:58 PM5/14/12
to Darshan, General Dart Discussion
On Mon, May 14, 2012 at 5:36 PM, Darshan <vincenz...@gmail.com> wrote:
> EventListenerList add(void handler(Event event), [bool useCapture])
>
> I can't find documentation for that

DOM events such as a button click first propagate downwards from the
topmost element (html -> body -> ... -> button). This is the 'capture
phase' (confusing name), and triggers any event handlers with
useCapture=true.
Then there's a 'bubble phase' where the event propagates upwards
(button -> ... -> body -> html), and triggers any event handlers
registered with useCapture=false.
At any point, an event handler can call event.stopPropagation() to
abort the whole thing.

So you use useCapture if you want your event handler to fire earlier
than others, e.g. to prevent other handlers from executing.
If two event handlers both use useCapture, the normal order is
reversed (the outer fires first, then the inner).

The canonical reference is probably
https://developer.mozilla.org/en/DOM/element.addEventListener
or
http://www.w3.org/TR/DOM-Level-3-Events/#capture-phase

Darshan

unread,
May 14, 2012, 3:12:29 PM5/14/12
to General Dart Discussion
So it's false by default?

On 14 Mag, 18:59, Sam McCall <sammcc...@google.com> wrote:
> On Mon, May 14, 2012 at 5:36 PM, Darshan <vincenzolasp...@gmail.com> wrote:
> > EventListenerList add(void handler(Event event), [bool useCapture])
>
> > I can't find documentation for that
>
> DOM events such as a button click first propagate downwards from the
[...]

Sam McCall

unread,
May 14, 2012, 3:58:06 PM5/14/12
to Darshan, General Dart Discussion

That's right.

Reply all
Reply to author
Forward
0 new messages