Reputation: 973
Is it conventional for parent function to return their child success callbacks or does it just depend on a case by case basis?
var cb = function(){
return 1;
}
function ret_cb(succ_cb) {
return(succ_cb ? succ_cb() : 1);
}
var succ = ret_cb(cb);
console.log(succ);
//or
function no_ret_cb(succ_cb) {
if(succ_cb){
succ_cb();
}
return 1;
}
succ = no_ret_cb(cb);
console.log(succ);
This would mainly be the reason I would use the callback
//functional way
succ = ret_cb(cb);
//vs
var some_value = "hello";
succ = ret_cb();
succ &= cb(some_value);
Upvotes: 0
Views: 356
Reputation: 943537
It's case by case.
It is rare for a function to take a callback and not be either asynchronous (in which case there is no return value from the callback to return until later) or operating in a loop (in which case there isn't one result of running the function to return).
Upvotes: 2