Skip to content

Instantly share code, notes, and snippets.

@fillano
Created March 30, 2014 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fillano/9866611 to your computer and use it in GitHub Desktop.
Save fillano/9866611 to your computer and use it in GitHub Desktop.
function * gen() {
console.log('start');
yield "called";
}
var g = gen();
//nothing happened
var a = g.next();
//顯示start
console.log(a.value);
//顯示called
console.log(a.done);
//顯示false
var b = g.next();
console.log(b.done);
//顯示true
g.next();
//在node.js環境中會拋出 Error: Generator has already finished
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment