That First Next Argument

Claude Pache claude.pache at gmail.com
Tue Aug 19 10:21:57 PDT 2014


Le 19 août 2014 à 15:21, Kevin Smith <zenparsing at gmail.com> a écrit :

> 
> // the same, advancing to the first `yield` at instantiation
> class echo2 extends echo {
>     construct(...args) {
>         let iter = super(...args)
>         iter.next()
>         return iter
>     }
> }
> 
> Nice pattern!  Would this also work?
> 
>     var skipFirst = genFn => function*(...args) { 
>         var iter = genFn(...args);
>         iter.next();
>         yield * iter;
>     };
> 
>     var echo2 = skipFirst(echo);
> 

Sadly, it doesn't work; for the delegated iterator always receives `undefined` for its first iteration. :-(
See [1], last algorithm of the section, step 5.

[1] http://people.mozilla.org/~jorendorff/es6-draft.html#sec-generator-function-definitions-runtime-semantics-evaluation 

—Claude
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20140819/eefb844d/attachment.html>


More information about the es-discuss mailing list