Skip to content

Commit 037b98c

Browse files
committed
doc: differences from standard APIs wrt UninitializedDOMTokenList
1 parent 13e9b4e commit 037b98c

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

README.md

+31
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,37 @@ To use the new binary you need to set the **`DENO_DOM_PLUGIN`** env var to the
139139
path of the binary produced in the previous step. **Don't forget** to run Deno
140140
with `--allow-env`.
141141

142+
## Inconsistencies with standard APIs
143+
144+
### Differences in `DOMTokenList`/`Element.classList`
145+
146+
To optimize memory usage, Deno DOM doesn't allocate `DOMTokenList`s
147+
(`Element.classList`) on `Element` creation, it instead creates an
148+
`UninitializedDOMTokenList` object. This can cause a subtle deviation
149+
from standard APIs:
150+
151+
```typescript
152+
const div = doc.createElement("div");
153+
154+
// Retrieve the uninitialized DOMTokenList
155+
const { classList } = div;
156+
157+
// Initialize the DOMTokenList by adding a few classes
158+
classList.add("foo");
159+
classList.add("bar");
160+
161+
// Inconsistency: the uninitialized classList/DOMTokenList
162+
// is now a different object from the initialized one
163+
164+
classList !== div.classList;
165+
166+
// However, the uninitialized DOMTokenList object still
167+
// works as the initialized DOMTokenList object:
168+
169+
classList.add("fizz");
170+
div.classList.contains("fizz") === true;
171+
```
172+
142173
# Credits
143174

144175
- html5ever developers for the HTML parser

0 commit comments

Comments
 (0)