O'Reilly logo
  • Ahmed Elgendy thinks this is interesting:

For all the events you’ve seen, to wire up a handler, you’ve always assigned the handler to some property, like onload, onmouseover or onclick. But not all events work like this—for example, with time-based events, rather than assigning a handler to a property, you call a function, setTimeout, instead and pass it your handler.

Here’s an example: say you want your code to wait five seconds before doing something. Here’s how you do that using setTimeout and a handler:


Cover of Head First JavaScript Programming


How could other events be handled?