<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript">
var a = 1;
var 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;
console.log( a, b, last );
};
}
var s1 = step( foo );
var s2 = step( bar );
s2();
s2();
s1();
s2();
s1();
s1();
s2();
console.log( a, b );
</script>
</head>
<body>
</body>
</html>
fdsgasgg
慕瓜9220888
名分开就是姓名
相关分类