1var btn = document.getElementById("btn");
2
3btn.addEventListener("click", handler, false);
4
5function handler(e) {
6 console.log("handler triggered");
7 doSomething();
8 console.log("handler done");
9}
10
11function doSomething() {
12 doThis();
13 doThat();
14 doTheOther();
15}
16
17function doThis() {
18 console.log("doThis - start & end");
19}
20function doThat() {
21 console.log("doThat - start");
22 // do something that takes a while
23 var stop = Date.now() + 1000;
24 while (Date.now() < stop) {
25 // wait
26 }
27 console.log("doThat - end");
28}
29function doTheOther() {
30 console.log("doThat - start & end");
31}