Proposal: Generator returning a value should throw SyntaxError

Brandon Benvie bbenvie at
Thu Sep 26 22:40:39 PDT 2013

On 9/26/2013 7:18 PM, Adam Ahmed wrote:
> Thanks, I see. The usage is for TaskResult sorts of things where the 
> scheduling is done via calls to `yield`, and the output of the 
> function is done via `return`. Fair enough. It still seems like a huge 
> footgun for the other cases which I'd expect are far more common than 
> cooperative scheduling, but I can respect that decision.

An example use case is delegating yield:

function* foo() {
   yield 'what';
   yield 'ever';
   return "DONE";

function* bar() {
   console.log(yield* foo());

This console.logs "DONE". Can't do this without a way to handle a return 
value from generators.

More information about the es-discuss mailing list