-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path8-callback-hell.js
More file actions
46 lines (42 loc) · 1.73 KB
/
8-callback-hell.js
File metadata and controls
46 lines (42 loc) · 1.73 KB
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
// CALLBACK HELL
// Seen the movie Inception? The movie talks about dreams within dreams within dreams,
// each layer with its own scope but can affect the previous layer of dream - if there
// is one. The worst scenario is that if you get lost, then you have no way of knowing
// where you are and where you came from.
// Replace dreams with JavaScript callbacks and you have the callback hell.
// Problems with Callbacks:
// 1)Callback Hell due to chaining.
// 2) each inner callback is dependent on its parent.
// 3) easy to break(due to error), and hard to debug.
// 4) highly coupled,not easily readable.
function getData(say,callback)
{
callback("abhinav is saying "+say+"! You want more?");
}
function getMoreData(say,callback)
{
callback("Rahul is saying "+say+"! You want more??");
}
function getSomeMoreData(say,callback)
{
callback("Gagan is saying "+say+"! You want more??");
}
function get_SomeMore(say,callback)
{
callback("Nirmal is saying "+say+"! GOODBYE!!!");
}
getData('Hi',function(result)
{
console.log(result);
getMoreData("Hello",function(res)
{
console.log(res);
getSomeMoreData("Kidaan",function(res)
{
console.log(res);
get_SomeMore("chad di kala",function(res){
console.log(res);
});
});
});
});