<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<link rel="stylesheet" href="">
</head>
<body>
<script >
let a = 1;
let b = 2;
function *foo() {
a ++;
yield;
b = b * a;
a = (yield b) + 3;
}
function *bar() {
b --;
yield;
a = (yield 8) + b;
b = a * (yield 2);
}
function step(gen) {
var it = gen();
var last;
return function() {
last = it.next(last).value
}
}
var s1 = step(foo);
var s2 = step(bar);
s2();
s2();
s1();
s2();
s1();
s1();
s2();
console.log(a,b)
</script>
</body>
</html>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…