I have a function parent, that calls child, and then does other stuff inside otherStuff:
function parent() {
child();
otherStuff();
}
Is it possible to modify child (and leave parent as is) so that the child call forces parent to return right after child returns? Will this be possible in EcmaScript 6?
Bad way to do this is to throw an exception in
child, which will bubble up toparentand then to the original caller. This approach makes an expectation for the original caller ofparentto catch the exception.You want to leave
parentas is, right?So, the ugly way is to let
childtemporarily modifyotherStuff:This way
otherStuffdoes nothing once and then goes back to the original state. Again, not only is it totally ugly, but makes an assumption aboutparent‘s structure.