#ele.scratch()
// Get all scratch data
ele.scratch(): Record<string, unknown> | undefinedRead all scratch data from the first element. Scratch is never exported and writes emit no events.
Record<string, unknown> | undefinedthe scratch object or value; undefined when empty or unset
Example
eles.scratch('ui', 1);console.log(eles.first().scratch().ui); // 1#ele.scratch(key)
// Get scratch data by key
ele.scratch(key: string): unknownRead one scratch namespace from the first element. Scratch is never exported and writes emit no events.
| Name | Description |
|---|---|
key: string | the namespace to read or write |
unknownthe scratch object or value; undefined when empty or unset
Example
eles.scratch('ui', 1);console.log(eles.first().scratch('ui')); // 1#eles.scratch(key, value)
// Set scratch data by key
eles.scratch(key: string, value: unknown): thisWrite one scratch namespace on every element. Scratch is never exported and writes emit no events.
| Name | Description |
|---|---|
key: string | the namespace to read or write |
value: unknown | the transient value to store |
thisthis collection, for chaining
Example
const result = eles.scratch('ui', 1);console.log(result === eles); // true#eles.scratch(patch)
// Set several scratch data fields
eles.scratch(patch: Record<string, unknown>): thisMerge scratch namespaces on every element. Scratch is never exported and writes emit no events.
| Name | Description |
|---|---|
patch: Record<string, unknown> | the namespaces to merge |
thisthis collection, for chaining
Example
eles.scratch({ ui: 1 });console.log(eles.first().scratch('ui')); // 1