by mathgladiator · 15y ago · 0 comments
Well, beyond a style issue. You can unfold the events and make it a lot less "annoying".
Consider,
var cb1 = function() {
}
var cb2 = function() {
req(cb1);
}var cb3 = function() {
req(cb2);
}req(cb3);
It's a lot cleaner and it looks like a state machine (and kind of looks like erlang/message passing).
There are actually a number of other ways to get around the function nesting issue as well.
var not_formatted;
var formatted;Might I suggest you take a look at my preferred solution for this,
var cb1 = function(callback) {
callback();
}
var cb2 = function(callback) {
req(function() {
callback();
});
}
var cb3 = function(callback) {
req(function() {
callback();
});
}
sequence([
cb1,
cb2,
cb3
]);
The sequencer is a simple lib function you can find at https://github.com/michiel/sequencer-js or using 'npm install sequencer'