Skip to content

Commit f5b05aa

Browse files
committed
update skill file to explain how possessives work
1 parent de86f4a commit f5b05aa

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

src/skills/EFFECTIVE_HYPERSCRIPT.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,59 @@ functions, variables) that operate on that element.
1414

1515
The language reads like English. Prefer natural phrasing over terse syntax.
1616

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.
69+
1770
## Magic Symbols
1871

1972
| Symbol | Meaning |

0 commit comments

Comments
 (0)