I'm trying to solve the last exercise of this JavaScript Closure Tutorial which takes about Continuation Passing.
This is the exercise:
Define a function named bothC similar to seqC that takes functions fC and gC and continuations success and failure. The functions fC and gC both just take success and failure continuations. Your function bothC should call both fC and gC no matter what, but only call success if both succeeded, and failure otherwise. Don't forget, your function will never return!
This seems to be a valid answer:
var bothC = function (fC, gC, success, failure) {
fC(
function() {
gC(success, failure);
},
function() {
gC(failure, failure);
}
);
};
But why can't I just do this?
var bothC = function(fC, gC, success, failure) {
fC(gC(success, failure), gC(failure, failure));
}