Skip to content

Commit

Permalink
Note about function scoping using blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
gnat authored Jun 1, 2024
1 parent 48a9604 commit 3b4572d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,12 +364,12 @@ me().on("click", async event => {

#### Scope functions inside `<script>`
* ⭐ On `me()`
* `me().doIt = (message) => { alert(message) }`
* `me().on('click', (ev) => { me(ev).doIt("hello") })`
* ⭐ Or, in an event: `me().on('click', ev => { /* add and call function here */ })`
* Or, use an inline module: `<script type="module">`
* `me().hey = (text) => { alert(text) }`
* `me().on('click', (ev) => { me(ev).hey("hi") })`
* ⭐ Use a block: `{ function hey(text) { alert(text) }; me().on('click', ev => { hey("hi") }) }`
* ⭐ Use an event: `me().on('click', ev => { /* add and call function here */ })`
* Use an inline module: `<script type="module">`
* Note: `me()` will no longer see `parentElement` so explicit selectors are required: `me(".mybutton")`
* Or, use backend code to generate unique names for anything not scoped by `me()`

#### Select a void element like `<input type="text" />`
* Use: `me('-')` or `me('prev')` or `me('previous')`
Expand Down

0 comments on commit 3b4572d

Please sign in to comment.