0

I am trying to access the property of an object passed back using yield.

function*test() {
 console.log(yield)
 console.log(yield(true).test)
}

var generator = test()

generator.next({ test: true })
generator.next({ test: true })
generator.next({ test: true })

However, the property is not accessed.

Object { test: true }
Object { test: true }

Am I misunderstanding something, or is this just the way it works and I should just assign the yield result to a temporary variable?

Daniel Herr
  • 19,083
  • 6
  • 44
  • 61

1 Answers1

1

You are misreading your parens. yield is a keyword, not a function.

console.log(yield(true).test)

is the same as

console.log(yield (true).test);

or

console.log(yield (true.test));

so you are still logging the result of the yield, the .test is not processing the value passed into .next.

You want

console.log((yield true).test);
loganfsmyth
  • 156,129
  • 30
  • 331
  • 251