Block lambda exiting function during execurtion

David Herman dherman at mozilla.com
Fri Jan 13 05:48:01 PST 2012


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.

Dave

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120113/2631b372/attachment.html>


More information about the es-discuss mailing list