Is it possible to trigger a function "return" from another function without the explicit keyword?
Example:
let a = function(){
//Option 1 - Duplicated on function aa
if(!bb()){
return false;
}
//Option 2 - No check needed as it's delegated on function b
b(this);
. . .
}
let aa = function(){
//Option 1 - Duplicated on function a
if(!bb()){
return false;
}
//Option 2 - No check needed as it's delegated on function b
b(this);
. . .
}
let b = function(fnc){
if(check)
fnc.return("hi");
}
let bb = function(){
if(check)
return false;
}
a(); //Returns "hi" if condition on function b meets
The problem that I want to solve is avoiding to duplicate the check on each function and avoiding to set the returning value (bool) on the parent function which can be different as it's explicitly defined each time.
What I'm asking is if there's any way to achieve this the way the "pseudo-code" does, with a higher abstraction level.
Thanks.