Merge pull request #1617 from javascript-tutorial/paroche-patch-10
Update article.md
This commit is contained in:
commit
79417c6e73
1 changed files with 3 additions and 3 deletions
|
@ -248,7 +248,7 @@ The "behavior" pattern can be an alternative to mini-fragments of JavaScript.
|
||||||
|
|
||||||
Event delegation is really cool! It's one of the most helpful patterns for DOM events.
|
Event delegation is really cool! It's one of the most helpful patterns for DOM events.
|
||||||
|
|
||||||
It's often used to add same handling for many similar elements, but not only for that.
|
It's often used to add the same handling for many similar elements, but not only for that.
|
||||||
|
|
||||||
The algorithm:
|
The algorithm:
|
||||||
|
|
||||||
|
@ -261,12 +261,12 @@ Benefits:
|
||||||
```compare
|
```compare
|
||||||
+ Simplifies initialization and saves memory: no need to add many handlers.
|
+ Simplifies initialization and saves memory: no need to add many handlers.
|
||||||
+ Less code: when adding or removing elements, no need to add/remove handlers.
|
+ Less code: when adding or removing elements, no need to add/remove handlers.
|
||||||
+ DOM modifications: we can mass add/remove elements with `innerHTML` and alike.
|
+ DOM modifications: we can mass add/remove elements with `innerHTML` and the like.
|
||||||
```
|
```
|
||||||
|
|
||||||
The delegation has its limitations of course:
|
The delegation has its limitations of course:
|
||||||
|
|
||||||
```compare
|
```compare
|
||||||
- First, the event must be bubbling. Some events do not bubble. Also, low-level handlers should not use `event.stopPropagation()`.
|
- First, the event must be bubbling. Some events do not bubble. Also, low-level handlers should not use `event.stopPropagation()`.
|
||||||
- Second, the delegation may add CPU load, because the container-level handler reacts on events in any place of the container, no matter if they interest us or not. But usually the load is negligible, so we don't take it into account.
|
- Second, the delegation may add CPU load, because the container-level handler reacts on events in any place of the container, no matter whether they interest us or not. But usually the load is negligible, so we don't take it into account.
|
||||||
```
|
```
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue