You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If we add parentheses, `sayThanks()` -- is a function call. So the last line actually takes the *result* of the function execution, that is `undefined` (as the function returns nothing), and assigns it to `onclick`. That doesn't work.
164
164
165
-
...But in the markup we do need the parentheses:
165
+
...On the other hand, in the markup we do need the parentheses:
The difference is easy to explain. When the browser reads the attribute, it creates a handler function with the body from its content.
171
+
The difference is easy to explain. When the browser reads the attribute, it creates a handler function with *body from its content*: `sayThanks()`.
172
172
173
-
So the last example is the same as:
173
+
So the markup generates this property:
174
174
```js
175
175
button.onclick=function() {
176
176
*!*
@@ -351,7 +351,7 @@ Some properties of `event` object:
351
351
: Event type, here it's `"click"`.
352
352
353
353
`event.currentTarget`
354
-
: Element that handled the event. That's exactly the same as `this`, unless the handler is an arrow function, or its `this` is bound to something else, then `event.currentTarget` becomes useful.
354
+
: Element that handled the event. That's exactly the same as `this`, unless the handler is an arrow function, or its `this` is bound to something else, then we can get the element from `event.currentTarget`.
355
355
356
356
`event.clientX / event.clientY`
357
357
: Window-relative coordinates of the cursor, for mouse events.
@@ -371,7 +371,7 @@ That's possible because when the browser reads the attribute, it creates a handl
371
371
372
372
## Object handlers: handleEvent
373
373
374
-
We can assign an object as an event handler using `addEventListener`. When an event occurs, its `handleEvent` method is called with it.
374
+
We can assign not just a function, but an object as an event handler using `addEventListener`. When an event occurs, its `handleEvent` method is called.
375
375
376
376
For instance:
377
377
@@ -388,7 +388,7 @@ For instance:
388
388
</script>
389
389
```
390
390
391
-
In other words, when `addEventListener` receives an object as the handler, it calls `object.handleEvent(event)` in case of an event.
391
+
As we can see, when `addEventListener` receives an object as the handler, it calls `object.handleEvent(event)` in case of an event.
0 commit comments