-
Notifications
You must be signed in to change notification settings - Fork 0
/
callbacks.js
52 lines (41 loc) · 959 Bytes
/
callbacks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//Callbacks are available from ES5
/*// Callbacks
function greet(name, callbacks) {
console.log('Hi' + ' ' + name);
callbacks()
}
// callback function
function callMe() {
console.log('I am callback function');
}
console.log('Before Timeout');
setTimeout(greet, 2000, 'John', callMe);
console.log('After Timeout');
*/
/*
setTimeout(greet, 2000, 'John', () => {
console.log('I am callback');
});*/
//greet('Peter', callMe); // Hi Peter
//Nested Callbacks
let someThing = (callback) => {
console.log("Do Something!");
callback();
}
let someThingElse = (callback) => {
console.log("Do Something Else!");
callback();
}
let doThirdThing = (callback) => {
console.log("Do Third thing!");
callback();
}
someThing(() => {
console.log("First anonymous callback!");
someThingElse(() => {
console.log("Second anonymous callback!")
doThirdThing(() => {
console.log("Third anonymous callback!");
})
})
})