/*Calling a generator function does not execute its body immediately; an iterator object for the function is returned instead. When the iterator's next() method is called, the generator function's body is executed until the first yield expression, which specifies the value to be returned from the iterator or, with yield*, delegates to another generator function.*/
/*function* welcome() {
console.log('call me next');
}
let x = welcome();
console.log(x);
var next = x.next();
console.log(next);
console.log(x.next());*/
/*function* welcome() {
console.log('call 1');
yield "How";
console.log('call 2');
yield "are";
console.log('call 3');
yield "you";
console.log('call 4');
}
//var gen = welcome();
//var one = gen.next();
//console.log(one);
//var two = gen.next();
//console.log(two);
//or
var gen = welcome();
for(let word of gen){
console.log(word);
}*/
// ex3
/*function* welcome() {
let catchYield= yield "How";
yield catchYield+"are";
yield "you";
}
let gen=welcome();
gen.next();
console.log(gen.next("catch ").value);*/
// ex4 generate infinite graph
/*function* graph() {
let x = 1,
y = 2;
while (true) {
yield {
x,
y
};
x += 3;
y += 2;
}
}
var g=graph();
console.log(g.next().value)*/
/*
//With a generator
function* makeSimpleGenerator(array){
var nextIndex = 0;
while(nextIndex < array.length){
yield array[nextIndex++];
}
}
var gen = makeSimpleGenerator(['yo', 'ya']);
debugger;
console.log(gen.next().value); // 'yo'
console.log(gen.next().value); // 'ya'
console.log(gen.next().done); // true */
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.