diff --git a/docs/ch13.md b/docs/ch13.md index a457e239910e07f9d396e7c0eef1af25f65c4af3..322a22d252201352e60a04e88547594b5ce45c8f 100644 --- a/docs/ch13.md +++ b/docs/ch13.md @@ -15,7 +15,7 @@ setTimeout(checkForUpdates, 60000); The first argument to setTimeout() is a function and the second is a time interval measured in milliseconds. In the preceding code, a hypothetical checkForUpdates() function will be called 60,000 milliseconds (1 minute) after the setTimeout() call. checkForUpdates() is a callback function that your program might define, and setTimeout() is the function that you invoke to register your callback function and specify under what asynchronous conditions it should be invoked. setTimeout() calls the specified callback function one time, passing no arguments, and then forgets about it. If you are writing a function that really does check for updates, you probably want it to run repeatedly. You can do this by using setInterval() instead of setTimeout(): - +```js // Call checkForUpdates in one minute and then again every minute after that let updateIntervalId = setInterval(checkForUpdates, 60000); @@ -25,9 +25,10 @@ let updateIntervalId = setInterval(checkForUpdates, 60000); function stopCheckingForUpdates() { clearInterval(updateIntervalId); } +``` ### 13.1.2 Events Client-side JavaScript programs are almost universally event driven: rather than running some kind of predetermined computation, they typically wait for the user to do something and then respond to the user’s actions. The web browser generates an event when the user presses a key on the keyboard, moves the mouse, clicks a mouse button, or touches a touchscreen device. Event-driven JavaScript programs register callback functions for specified types of events in specified contexts, and the web browser invokes those functions whenever the specified events occur. These callback functions are called event handlers or event listeners, and they are registered with addEventListener(): - +```js // Ask the web browser to return an object representing the HTML //