Block lambda exiting function during execurtion
On Jan 13, 2012, at 4:27 AM, François REMY wrote:
To be useful, I think the behavior should be
(1) yes (2) yes (3) doesn’t happen; see 2. (4) doesn’t happen; see 2.
That's correct. The return is bound to getAnyWhere and breaks out of the forEach loop.
However, it seems rather complex since the “forEeach” function could be any host function that was not mean to be aborted at any given time by callee.
You can already break out of a host function with exceptions.
If the response to (1) is no, I don’t see the point of ‘return’ returning from parent function. Did I miss something?
I think Yehuda says it best:
http://yehudakatz.com/2012/01/10/javascript-needs-blocks
For my money, the biggest wins of block lambdas are:
a) the lightweight syntax for small callbacks
b) being able to abstract over things like break
and continue
and return
in a natural way
c) being able to build control abstractions from code generators like CoffeeScript or (in the future) macros
Of those, b) and c) depend on return
returning from the parent function.
I’ve a question about block lambda. What will be the output of the console for this code :
One could resume my question in three smaller ones :
(1) does the first 'block lambda return’ returns its value to fv directly. (2) does the first ‘block lambda return’ aborts the forEach (3) does the second ‘block lamdba return’ (if any) causes an error to be thrown (4) does the execution of console.log(fv) continue in parallel with the following forEach iterations
To be useful, I think the behavior should be
(1) yes (2) yes (3) doesn’t happen; see 2. (4) doesn’t happen; see 2.
However, it seems rather complex since the “forEeach” function could be any host function that was not mean to be aborted at any given time by callee.
If the response to (1) is no, I don’t see the point of ‘return’ returning from parent function. Did I miss something? François