Environment APIs
Most of our interaction with the browser will be done in the same pattern – you will define a function, and pass that function as a parameter to some browser API. When and if that function will actually be scheduled for execution will depend on the particulars of that API. In the previous case, you used the event handler API, addEventListener
, which takes two parameters, the name of an event, and the code that will be scheduled when that event happens.
Note
You can get a list of different possible events at https://developer.mozilla.org/en-US/docs/Web/Events.
In the rest of this chapter, you will use two other APIs as well, the environment's method to defer some code for later execution (setTimeout
) and the ability to call on external resources (popularly called AJAX). There are two different AJAX implementations that we will be working with, the original XMLHttpRequest
implementation, and the more modern and flexible fetch
implementation.