Comparison
Chain of responsibilityvsEvent bubbling
Chain of responsibility
the request went to the first handler, which passed it on, and somewhere down the line something answered it.
Passing a request along a sequence of handlers until one of them deals with it, so the sender does not know which will. HTTP middleware stacks, servlet filters and event bubbling in the DOM are all this pattern. Its characteristic failure is silence: if no handler takes the request, nothing happens and nothing says so, which is why a terminal handler that raises is nearly always worth adding.
Full entry →Event bubbling
you clicked the button and the click handler on its container ran too, without you binding anything there.
The second phase of event dispatch, in which the event travels from the target back up through every ancestor to the document, firing listeners at each. It is the default phase for `addEventListener`, and it is what makes a single handler on a container able to serve every descendant. It is also why a click inside a modal can close the dropdown behind it, unless something stops the propagation.
Full entry →