This commit is contained in:
Ilya Kantor 2017-03-21 14:41:49 +03:00
parent 4ae129054e
commit ab9ab64bd5
476 changed files with 3370 additions and 532 deletions

View file

@ -0,0 +1,16 @@
The answer: `1` and `2`.
The first handler triggers, because it's not removed by `removeEventListener`. To remove the handler we need to pass exactly the function that was assigned. And in the code a new function is passed, that looks the same, but is still another function.
To remove a function object, we need to store a reference to it, like this:
```js
function handler() {
alert(1);
}
button.addEventListener("click", handler);
button.removeEventListener("click", handler);
```
The handler `button.onclick` works independantly and in addition to `addEventListener`.

View file

@ -0,0 +1,17 @@
importance: 5
---
# Which handlers run?
There's a button in the variable. There are no handlers on it.
Which handlers run on click after the following code? Which alerts show up?
```js no-beautify
button.addEventListener("click", () => alert("1"));
button.removeEventListener("click", () => alert("1"));
button.onclick = () => alert(2);
```