更新时间:2022-06-09 21:26:14
生成器看起来像这样:
function test() {
// first part of function
yield;
// second part of function
yield;
}
var gen = test(); // creating a generator
gen.next(); // execute first part
button.onclick = function () {
gen.next(); // execute second part on button click
};
现场演示: http://jsfiddle.net/MQ9PT/
然而,这并不适用于Firefox。它将成为下一版的ECMAScript标准的一部分。
This however doesn't work beyond Firefox. It will become part of the ECMAScript standard in the next edition...