Javascript Generator pass value to next() method

Introduction

Use the next() method that is part of the iterator object to pass properties to the generator.

function *returnMSG(){ 
     let value = yield value 
     return value; 

} 

let it = returnMSG(); 
console.log(it.next()); //Object {value: undefined, done: false} 
console.log(it.next('things')); //Object {value: "things", done: true} 



PreviousNext

Related