i have a function which calls the another function and so on.
function A(args,callback){
// make ajax request
// on response
B()
}
function B(args){
// make ajax request
// on response
C()
}
function C(args){
// make ajax request
// on response
D()
}
I am making such ten ajax calls. Two questions...
Inside D()
there is no way to call callback
because it is not defined there. What I mean by this is as long as you don't pass arguments
down the callbacks then you are not having your callback
variable inside D()
. Callback hell is a situation where callbacks call each-other meaning A()
calls B()
and B()
calls A()
.
What is "callback hell"?
Asynchronous javascript, or javascript that uses callbacks, is hard to get right intuitively.
2.No, callback
is not defined inside D
so you will get an Error.
We can pass function reference as a parameter in JavaScript and use this reference to call related function whenever/ wherever we want.
for more info see this link http://recurial.com/programming/understanding-callback-functions-in-javascript/