I've been unable to find a simple example of a javascript callback pattern for my purpose and an answer to the following question would be very helpful.
Supposing I've 2 functions which each display an alert:
function hello1() {
setTimeout(function(){
alert("hello1");
}, 500);
}
function hello2() {
alert("hello2");
}
if I'm using this function,
function saythehellos()
{
hello1();
hello2();
}
the alert "hello2" will display first followed by the alert "hello1"
How can I change the function saythehellos() using a callback pattern so that the alert "hello1" is displayed first followed by the alert "hello2"?