生成器函数参数

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script>
// 生成器函数第一种传参方法
function*fn(arg){
console.log(arg);
let one = yield 111;
let two = yield 222;
let three=yield 333;
}
let result = fn('aaa');
console.log(result.next());
</script>

<script>
// 生成器函数第二种传参方法
function*fn(arg){
let one = yield 111;
console.log(one);
let two = yield 222;
console.log(two);
let three=yield 333;
}
// 执行获取迭代器对象
let result = fn();
console.log(result.next());
// next方法可以传入实参
console.log(result.next('bbb'));
console.log(result.next('ccc'));
</script>
</body>
</html>

posted @ 2020-08-14 10:42  Smile*^  阅读(186)  评论(0编辑  收藏  举报