Chapter 14. Handling Events
âYou have power over your mindânot outside events. Realize this, and you will find strength.â
âMarcus Aurelius, Meditations
Some programs work with direct user input, such as mouse and keyboard interaction. The timing and order of such input canât be predicted in advance. This requires a different approach to control flow than the one we have used so far.
Event Handlers
Imagine an interface where the only way to find out whether a key on the keyboard is being pressed is to read the current state of that key. To be able to react to keypresses, you would have to constantly read the keyâs state so that youâd catch it before itâs released again. It would be dangerous to perform other time-intensive computations ...
Get Eloquent JavaScript, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.