Merge pull request #1617 from javascript-tutorial/paroche-patch-10

Update article.md
This commit is contained in:
Peter Roche 2019-11-19 00:06:54 -07:00 committed by GitHub
commit 79417c6e73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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.
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:
@ -261,12 +261,12 @@ Benefits:
```compare
+ Simplifies initialization and saves memory: no need to add many 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:
```compare
- 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.
```