Function Callbacks:
Call backs are functions passed into another function as an argument. This callback function is then invoked from inside the outer function to complete some routine or action:
The function ask()
has 3 paramenters, question, yes, no
within it, plus an if... else
comprarator,
with its function confirm
and parameter being the ask
function parameter question
.
Inside the if... else
comparator is another function, either yes()
or no()
.
These functions have been set outside of the function ask()
but are calling inside it, and thus are callback functions.
Outside of this function, the functions yes()
or no()
(which are parameters of the ask()
function) will do what the attributed code says.
Outside of the functions, we call the function using ask("Are you ok?", yes, no);
and the according answer displays beneath our button.
An alert box asks the question and gives us options.
Depending on the option we choose, the results of the if... else
comparators are logged.