-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCallBackHell.js
More file actions
40 lines (33 loc) · 1 KB
/
CallBackHell.js
File metadata and controls
40 lines (33 loc) · 1 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
// inversion control:
orderPlace(cart, function redirectToPayment(orderId) {
console.log("payment");
});
// here we lost our control on the function which we are passing through another
// this is defined as inversion AbortController
// so to avoid that we use
const promis = orderPlace();
promis.then(function redirectToPayment() {
console.log("payment")
});
// callback hell:
orderPlace(cart, function (orderId) {
redirectToPayment(orderId, function (orderId) {
orderSummary(paymentId, function (paymentId) {
console.log("summary");
})
});
});
const promise = orderPlace();
promise.then(
function (orderId) {
return redirectToPayment(orderId);
}).then(function (paymentId) {
return orderSummary(paymentId);
})
const promises = orderPlace()
.then(function (orderId) {
return redirectToPayment(orderId);
})
.then(function (paymentId) {
return orderSummary(paymentId);
})