Example 1:
function *topicList(){
yield "ES2015";
yield "Semi-colons: good or bad?";
yield "TypeScript";
} for( let topic of topicList() ){
console.log( topic );
}
Example2:
let user = {
name: "sam", totalReplies: 17, isBlocked: false
}; user[Symbol.iterator] = function *(){ let properties = Object.keys(user); for(let p of properties){
yield this[p];
}
}; for(let p of user){
console.log( p );
}