0

In the following:

function *bar() {
    console.log( yield 1 );
    console.log( yield 2 );
    console.log( "done" );
}
var it = bar();
it.next();

it2 = fromTheTop(it); 
function fromTheTop(it){
   // ???
}

How could you write the fromTheTop function to create a new iterator for the same source as it came? Notice, I'm not trying to clone the argument, so other questions such as this one are not quite right. I'm new to generators in JS, so maybe it's just a matter of phrasing the question ? TIA !

Community
  • 1
  • 1
Dean Radcliffe
  • 2,154
  • 20
  • 28

1 Answers1

1

I don't think that information (where it came from) is available from an iterator. At least, I'm not seeing anything to suggest it is.

T.J. Crowder
  • 879,024
  • 165
  • 1,615
  • 1,639