The generator.next() method

# Michaël Rouges (12 years ago)

I wondered why it would be possible to send only one variable via this method?

Knowing that we will have the opportunity to use destructuring assignments, why can't we deal on this "problem"?

# Forbes Lindesay (12 years ago)

It already is dealt with via destructuring assignments:

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)
# Brendan Eich (12 years ago)

No .value anywhere, though.

# André Bargull (12 years ago)

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

# Forbes Lindesay (12 years ago)

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

# Domenic Denicola (12 years ago)

I believe .value is indeed correct, although as André alludes to, .send() has been replaced by .next().

Working example in Traceur (this is fun!)

# Brendan Eich (12 years ago)

André Bargull wrote:

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

Sorry (to Forbes), I was thinking of when for-of orchestrates.

# Brendan Eich (12 years ago)

Domenic Denicola wrote:

[Working example in Traceur][1] (this is fun!)

Yes, +lots for Traceur.

# Forbes Lindesay (12 years ago)

I'd rather be corrected when I'm right than ignored when I'm wrong, and at the moment I'm still pretty new to the specifics of ES6 APIs :)