Reputation: 3560
Im not understand the idea, wrong was happened in this code:
Output always undefined for first item...(Also if I set another yieldData5.next(...) after last line of code, it will be print on console
(undefined
bye : taher
undefined)
thanks,
Upvotes: 1
Views: 73
Reputation: 816970
Output always undefined for first item
You are not passing anything to the function, so i
is undefined
and therefore yield i;
is equivalent to yield undefined;
. You are explicitly yielding undefined
from the function, and that's what you see.
If your question is how to reference the value passed to the first call of .next
, the answer is unfortunately: You can't.
This is being addressed in the next version of ECMAScript.
Upvotes: 2
Reputation: 12892
Try:
let yieldData5 = collection_name5({index: 0, masg: 'Hi');
console.log(collection_name5.next({index: 2, masg: 'bye').value);
Upvotes: 0