javascript - Nesting callbacks for more than two tasks -
it possible determine order of two tasks using callbacks, shown below.
a(b); function a(callback) { // callback(); } function b() { // next }
see fiddle
first a()
, b()
.
i concatenate more 2 tasks. i´m dealing quite big functions, i´m looking that:
a(b(c));
first a()
, b()
, c()
. i'm not successful this. see fiddle
is there easy way so, maybe without needing promises?
you're calling b
immediately, not passing callback a
. you'll need use function expression:
a(function(aresult) { b(c); });
of course, can avoid these returning closures functions:
function a(callback) { return function(args) { // if (callback) callback(res); }; } function b(callback) { return function(aresult) { // next if (callback) callback(res); }; } function c(callback) { return function(bresult) { // next if (callback) callback(res); }; }
which call this:
a(b(c())();
(this known pure continuation passing style)
Comments
Post a Comment