The generator.next() method

Forbes Lindesay forbes at lindesay.co.uk
Fri Aug 23 05:44:54 PDT 2013


I just wanted to demonstrate the point, I couldn't remember what the exact API agreed upon for `gen.send` is.

On 23 Aug 2013, at 10:07, "Andr? Bargull" <andre.bargull at udo.edu<mailto:andre.bargull at udo.edu>> wrote:

`g.next()` returns `{value: [1, 2, 3], done: false}` for me, so .value is needed here. Or do you mean something else?

Thanks,
Andr?


No .value anywhere, though.

/be

Forbes Lindesay wrote:
> It already is dealt with via destructuring assignments:
>
> ```js
> function* gen() {
>    var {x, y, z} = yield [1, 2, 3]
>    return x&&  y || z
> }
> var g = gen()
> var [a, b, c] = g.next().value
> assert(a === 1)
> assert(b === 2)
> assert(c === 3)
> var res = g.send({x: true, y: false, z: true}).value
> assert(res === true)
> ```
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130823/abd8121d/attachment-0001.html>


More information about the es-discuss mailing list