CALLBACK PARADIGMA

Showing the basic structure for providing API with a callback

We have already introduced callback functions in the basic tutorial (here and here). Now we want to show a plain example of callback usage, emulating a call to a remote server. To keep things as simple as possible, instead of calling an actual backend page (which requires some backend coding skills), we just return an hard-coded value after a timeout delay. Such delay is set using the Javascript setTimeout() function.

This example can look like a repetition of the concepts already introduced in the basic tutorial. This is true, but such repetition should help us to compare the callback paradigma with the promises paradigma, which will be the focus of the next lesson.

Sources

HOME