Everytime I do gen().next(); I always get Object {value: “test1”, done: false} (which is wrong,the generator should move on). Whereas if I call it like res1.next() (which is EXACTLY the same thing, since res1=gen()) it runs correctly until the end. Why is this happening? Have I misunderstood something?
So in your example variable g corresponds to my function gen right?
This means that everytime we call a genarator function it returns a new generator object.