Generation ticket cancellation pattern
Use a generation ticket to let only the most recently started operation update state, provided it is still current. Older work can finish without overwriting that state.
CKTIS / JavaScript
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
Use a generation ticket to let only the most recently started operation update state, provided it is still current. Older work can finish without overwriting that state.
Both forms define synchronous generator functions. A declaration introduces a name in scope, while a method belongs to an object or class.
Write base-16 integers with `0x` or `0X`, and add `n` when you need an exact `BigInt` value rather than a potentially rounded `Number`.
`href` specifies the link's address; `target` tells the browser which browsing context to use when following it.
Read or set a link’s `target` attribute, and distinguish its stored value from the browsing context the browser selects when the link is followed.
Choose a rendering context with `getContext()` and size its bitmap with `width` and `height`. Unlike CSS sizing, writing either dimension clears the bitmap and resets drawing state in 2D mode.
`canvas.width` and `canvas.height` size the bitmap, not the CSS display box. With a 2D context, even assigning the current value clears the drawing and resets the drawing state.
Separate source and target events so you can set drag data, accept a drop, read the payload, and clean up even when a drag is canceled.
`HTMLElement` is the base class for autonomous custom elements. Invoke its constructor through `super()` in a subclass, not directly with `new HTMLElement()`.
`draggable` controls whether an element can be a drag source. `tabIndex` influences whether and when Tab navigation reaches it. Setting one property does not replace setting the other.
`hidden` reflects an HTML attribute, while `click()` dispatches a synthetic click. Hiding an element does not disable it or prevent a programmatic click.
Reading `innerHTML` serializes an element’s contents as markup. Assigning to it replaces the contents with parsed nodes, even when the assignment uses `+=`.
Distinguish the height of an element’s outer box, the height of its inner viewing area, and its current vertical scroll position. Learn to detect the bottom without relying on exact numerical equality.
Set an element’s transform and height from JavaScript, and distinguish inline declarations from the values resolved by the CSS cascade.
Read, set, or remove an element’s inline `scroll-behavior` declaration, and distinguish it from the resolved CSS value and a per-call scrolling option.
Use `style.transform` to change an element’s visual geometry and `style.touchAction` to control which panning and zooming gestures the browser may handle. Both write inline CSS declarations.
Use `element.style.width` and `element.style.height` to read, set, and remove inline CSS declarations. Reading a declaration is not the same as measuring the element.
Use `disabled` to make an HTML form control unavailable for user interaction and exclude it from validation and form data. The `.disabled` property and `:disabled` selector answer different questions.
Use `input` to react to edits and `submit` to handle form submission at the right point in the validation flow.
`contentWindow` gives you a reference to the iframe’s window, while `load` tells you that the browser has finished a load attempt. Neither confirms success or grants DOM access.
Read an image’s natural size in CSS pixels and distinguish request completion from successful loading or decoding.
Set an image URL and alternative text, then handle successful and failed image loads using events on the image element.
Read and update a form control’s value independently of whether the user can interact with it. Distinguish an element’s own `disabled` attribute from its effective disabled state and see which values make it into form data.
`max` reflects the upper limit as a string, while `disabled` reflects whether the input has its own disabling attribute. Exceeding the limit does not disable the input.