Canvas 2D: transforms, rectangles, and paths
Keep the transform, the pixels, and the default path separate. Learn when coordinates are transformed, which calls change pixels immediately, and what remains after `stroke()`.
CKTIS / JavaScript
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
Keep the transform, the pixels, and the default path separate. Learn when coordinates are transformed, which calls change pixels immediately, and what remains after `stroke()`.
Separate drawing state from the current path and bitmap so you can limit clipping to one drawing operation and clear only the intended pixels.
Create instances with `new`, initialize their state in `constructor`, and distinguish prototype methods from static methods and `super()` from `super.method()`.
A constructor initializes the object created by `new`, instance methods are shared through the prototype, and static methods belong to the class.
Use `constructor` to set up an object created with `new`. In a derived class, `super()` makes `this` available.
Bracket notation `obj[expr]` selects a property using the value of an expression. Use it to read or write properties or call methods whose keys are determined at runtime.
Use `console.log()` for routine diagnostics and `console.error()` for error-level messages. Writing an error message is not the same as throwing an exception.
Set individual border widths and a CSS transform through `element.style`, and distinguish inline declarations from the values the browser resolves after applying the cascade.
Use a finite-state tokenizer to identify CSV fields and a parser to assemble records without splitting at commas or line breaks inside quoted values.
Use `disconnectedCallback()` to release resources tied to a custom element’s connection to a document, while keeping the instance ready to reconnect.
Learn how a custom element chooses which attributes to observe and how it reacts to attribute writes, connection to a document, and disconnection.
Use `detail` to carry data in a custom event and `bubbles` to let non-capturing listeners on ancestors receive it after the target phase.
The source sets which operations are allowed, the target selects one, and `setData()` stores the text the target can read on drop.
Read two bytes from a DataView as an unsigned 16-bit integer, choosing the byte order specified by the data format.
`getUTCFullYear()` reads the UTC year. `setUTCFullYear()` changes the same `Date` and returns its new timestamp. Omitting an argument is not the same as passing `undefined`.
`debounce` combines a burst of calls into one. In the version shown here, only the last call runs, after the calls have paused.
Use `parameter = expression` in a function definition to supply a value when the corresponding argument is omitted or explicitly passed as `undefined`.
A destructuring default replaces only `undefined`. It preserves `null`, `false`, and `0`, and the fallback expression runs only when needed.
Put patterns directly in a function’s parameter list to read object properties or values from an iterable. Learn how whole-parameter defaults differ from defaults inside a pattern.
Use `document.body` to access the page’s content element and `document.documentElement` to access the document’s root element. Either property can return `null`.
Use `document.body` to access the page’s content element and `document.title` to read or change the document’s title text.
`document.getElementById(id)` finds an element by its ID, while `document.activeElement` reports where the document sees keyboard focus right now.
Use `getElementById()` to find an element by its ID, and `document.body` to access the document’s body element whether or not it has an ID.
`getElementById()` finds an element by its exact ID, while `documentElement` gives you the document's root element. Both can yield `null`, but for different reasons.