Skip to content

Instantly share code, notes, and snippets.

@noel9999
Created July 26, 2017 04:42
Show Gist options
  • Save noel9999/71363d9fb3386d581558708b66af79c1 to your computer and use it in GitHub Desktop.
Save noel9999/71363d9fb3386d581558708b66af79c1 to your computer and use it in GitHub Desktop.
es6 generator weird demo
var yieldValueBox = [];
var nextValueBox = []
function * god () {
for (var i = 0; i < 5; i++) {
a = yield ({index: i, time: (new Date()).getTime()})
yieldValueBox.push(a)
console.log('Next passed: ', a);
}
}
var g = god();
[1,2,3,4,5,6].forEach(function(element) { nextValueBox.push(g.next(element)) })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment