Answer: Yes , it can be optimized by the proposed method , if it was native code .
To understand what will happen, simplify this code, which is important here, first:
var result = false; for (var i in obj) { if (result || (result = call(i))) return; }
This means that if either result no longer false, it will return, or if call() returns the wrong value, it will return. Since the result changes only to call() , the first check on result is redundant.
var result = false; for (var i in obj) { if (result = call(i)) return; }
This code will still be returned as soon as call() delivers the wrong value.
In addition, since each() is a library function, and the OP returns a breaker on the found element
what really happens:
var result = false; for (var i in obj) { if (result || (result = call(i))) break; }
In this case, the code can still be optimized by the proposed method if the library foreach function is used. The cycle will be left at the found value.
The confusing part is that each() is a library function and uses a function to simulate a loop body. Returning the breaker library constant from the body function will exit the loop.
Once each() decides to use its own .forEach() , the code can no longer be optimized , since .forEach() will not understand the return value of breaker ! See thg435's answer for details!