-
Notifications
You must be signed in to change notification settings - Fork 806
Description
In Chapter 15 - Section on "Event Objects" near the top:
In the 2nd edition it is written: "we can look at the event object’s which property." And then the example uses 3 cases of object.which.
In the 3rd edition it is written: we can look at the event object’s button property." And then the example uses 1 case of object.button, then 2 cases of object.which.
They seem to both work. But this could be a bit more clear/consistent, as it is in the 2nd edition. There seems to be more documentation on event.which than event.button. However event.button is more intuitive.
The section could perhaps be re-written as:
"Though we have ignored it so far, event handler functions are passed an argument: the event object. This object holds additional information about the event. For example, if we want to know which mouse button was pressed, we can look at the event object’s button property.
<button>Click me any way you want</button>
<script>
let button = document.querySelector("button");
button.addEventListener("mousedown", event => {
if (event.button == 0) {
console.log("Left button");
} else if (event.button == 1) {
console.log("Middle button");
} else if (event.button == 2) {
console.log("Right button");
}
});
</script>
"