You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/skills/EFFECTIVE_HYPERSCRIPT.md
+53Lines changed: 53 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,59 @@ functions, variables) that operate on that element.
14
14
15
15
The language reads like English. Prefer natural phrasing over terse syntax.
16
16
17
+
## Style: Write English, Not Code
18
+
19
+
### `the` — Semantic Sugar
20
+
21
+
The word `the` can be inserted almost anywhere for readability. It has no semantic meaning and is ignored by the parser:
22
+
23
+
```hyperscript
24
+
-- These are identical:
25
+
set innerHTML of #d1 to "hello"
26
+
set the innerHTML of the #d1 to "hello"
27
+
28
+
get the first <li/> in the <ul/>
29
+
get first <li/> in <ul/>
30
+
```
31
+
32
+
Always use `the` when it makes the line read more naturally.
33
+
34
+
### Property Access: Prefer English Order
35
+
36
+
_hyperscript offers three ways to access properties. Prefer the most readable form:
37
+
38
+
**Possessives** — the standard form. Use `'s` for named elements, and `my`, `its`, `your` for the special implicit targets:
39
+
40
+
```hyperscript
41
+
set #output's innerHTML to "done"
42
+
get the event's detail
43
+
set the closest <div/>'s style to ""
44
+
45
+
set my innerHTML to "hello" -- "my" refers to me
46
+
put its name into me -- "its" refers to it (the result)
47
+
log your style.color -- "your" refers to you (in tell blocks)
48
+
```
49
+
50
+
**`of` expressions** — an alternative form that is particularly useful when you want to avoid the tight binding of possessives, since `of` binds more loosely:
51
+
52
+
```hyperscript
53
+
-- without "of", you'd need parentheses:
54
+
get (the closest <ul/>)'s children
55
+
56
+
-- with "of", it reads naturally:
57
+
get the children of the closest <ul/>
58
+
```
59
+
60
+
**Dot notation** — good for method invocation and acceptable in general, although the other forms are preferred for readability:
61
+
62
+
```hyperscript
63
+
element.classList.add('active') -- method calls: dot is natural
64
+
element.dataset.id -- deeply nested access: dot is practical
65
+
my.style.color -- acceptable but "my style's color" is more hyperscript-y
66
+
```
67
+
68
+
**Guideline:** If you can read the line aloud and it sounds like English, you've picked the right form. `#output's innerHTML` reads better than `#output.innerHTML`. Use `of` when possessives would require parentheses.
0 commit comments