UNPKG

myplayaaaaa

Version:

wwww

29 lines (27 loc) 1.02 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script> //创建一个generator函数 function* test(){ yield console.log("tom"); // 暂停--阻塞 yield console.log("jarry"); //暂停 yield console.log("susan");//暂停 } //调用generator函数,返回一个遍历器对象 //generator函数是遍历器对象生成器 let iter = test(); //使用遍历器对象的next()方法,遍历generator函数每个内部状态 yield //执行yield后面的语句,将yield后面语句的值当做 next方法返回值的value值 iter.next();//{value:undefined,done:false} //从当前位置开始执行,直到遇到下一个yield后面的语句,将yield后面语句的值当做 next方法返回值的value值 iter.next();//{value:undefined,done:false} iter.next();//{value:undefined,done:false} iter.next();//{value:undefined,done:true} </script> </head> <body> </body> </html>