How can you tell what generator an iterator is for in ES6?

46 views Asked by At

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 !

1

There are 1 answers

0
T.J. Crowder On

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.