yield* desugaring

Allen Wirfs-Brock allen at wirfs-brock.com
Tue May 14 08:28:27 PDT 2013


On May 14, 2013, at 8:12 AM, Andreas Rossberg wrote:

> On 14 May 2013 17:07, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:
>> 
>> What about providing a convenience "resume" method on generators to help clarify co-routine style usage?  Dave suggested that "resume" was pedagogically useful.
>> 
>> I would define it equivalently two:
>> 
>>   resume(...args) {return this.next(...args};
>> 
>> (resume rather than next delegates to avoid the delegation for normal for-of iterations)
> 
> Not sure about having two names for the same method, but if so, why
> not simply make Generator.prototype.resume ===
> Generator.prototype.next?

It could me done that way.  I'm not so sure it is such a good practice.  GeneratorFunctions are constructors and hence each one provide a unique prototype object for all its instances.  So, conceivably a developer can over-ride either or both of "next" and "resume" for a particular family of generators. Specify one as explicitly delegating to the other in the "superclass" makes it clearer which method you need to over-ride if you want to modify both "next" and "resume" behavior.   Otherwise, you would always have to remember to over-ride both.

Allen


More information about the es-discuss mailing list