Skip to content

Commit

Permalink
New notes about scoping variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
gnat authored Aug 28, 2024
1 parent 60beecf commit a3d690a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,17 @@ me().on("click", async event => {
* `e`, `ev`, `evt` = event
* `f`, `fn` = function
#### Scope functions inside `<script>`
* ⭐ On `me()`
#### Scope functions and variables inside `<script>`
* ⭐ Use a block
* `{ let scoped = 1; function hey(text) { alert(text) }; me().on('click', ev => { hey("hi") }) }`
* `let` is scoped in `{ }` blocks!
* ⭐ Use `me()`
* `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 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")`
* Warning: When using a module `me()` can no longer see `parentElement`, this means explicit selectors are required: `me(".mybutton")`
#### Select a void element like `<input type="text" />`
* Use: `me('-')` or `me('prev')` or `me('previous')`
Expand Down

0 comments on commit a3d690a

Please sign in to comment.