Cancel an external function from the function it calls

Can youth do return / stop from box ? Directly, not something like:

 function youth(){ var check = true; function box(){ //code check = false; } //code while(check){ //code; } return false; } 

(where there is a check variable that changes box )

+4
source share
1 answer

No, you cannot, unless you throw an exception from the internal function (but this is not really considered a “return”), and in any case this is not a very good design pattern).

It doesn't make sense to let the function have its caller return a value, because the caller may not even be declared in the same context - maybe it's some other function that takes an argument of the function and that passed -in should not change the behavior the function being called.

+8
source

Source: https://habr.com/ru/post/1334029/


All Articles