Skip to the content

Event rule

Examine rule C13 with your own clicks.

The rule

An event listener operates in the context of the code that dispatches the event, if that context is not the root context. Else, the listener operates in the context of the addEventListener() use, or of the assignment to the on... property.

Examine the rule

  1. Add a listener in context A.
  2. Set onclick in context B.
  3. Click the large button. The browser dispatches the event, so each handler gets its registration context.
  4. Dispatch a click from context C. Code in context C dispatches the event, so each handler gets C.

Add the handlers, then click the button. Each click adds a line here.

A green line is a click in which the handler got the context of the rule. A red line is a click in which it did not.

async-browser-context: AsyncLocalStorage and the TC39 AsyncContext API for browsers. The source code is on GitHub.

To change a page, edit its file in site/content/. The writing style guide tells you how.

An AI model (Claude, from Anthropic) wrote most of the text and the code of this site and of the library, under the direction of the author. The tests and the STE linter examine them.