Skip to content

Instantly share code, notes, and snippets.

@gitexec
Created November 27, 2017 14:50
Show Gist options
  • Save gitexec/c1cea6acbacd25310a21ac8ccf03eaab to your computer and use it in GitHub Desktop.
Save gitexec/c1cea6acbacd25310a21ac8ccf03eaab to your computer and use it in GitHub Desktop.
Iteration with symbol
var randoms = {
[Symbol.iterator]: function() {
return {
next: function() {
return { value: Math.random() };
}
};
}
};
var randoms_pool = [];
for (var n of randoms) {
randoms_pool.push( n );
// don't proceed unbounded!
if (randoms_pool.length === 100) break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment