18.生成器的函数参数
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
function* gen(arg) {
console.log(arg);
let one = yield 111;
console.log(one);
let two = yield 222;
console.log(two);
let three = yield 333;
console.log(three);
}
let iterator = gen("AAA");
// iterator.next();
console.log(iterator.next()); //next方法可以传入实参,实参就是真个yield表达式返回的结果
console.log(iterator.next("BBB")); //当前next的参数会作为上一个yield语句的返回值
console.log(iterator.next("CCC"));
console.log(iterator.next("DDD"));
</script>
</body>
</html>