Skip to content

Instantly share code, notes, and snippets.

@DmitrySoshnikov
Created March 13, 2011 14:32
Show Gist options
  • Save DmitrySoshnikov/868132 to your computer and use it in GitHub Desktop.
Save DmitrySoshnikov/868132 to your computer and use it in GitHub Desktop.
Infinite objects generator
/**
* by Dmitry Soshnikov <[email protected]>
*/
// infinite objects generator
let g = new function () {
while (true) {
yield;
}
};
// generate an array of 3 objects
let objects = [1, 2, 3].map(function(i) g.next());
console.dir(objects);
// Result:
//
// [
// [[Class]]: "Array",
// length: 3,
// 0: {
// [[Class]]: "Object"
// },
// 1: {
// [[Class]]: "Object"
// },
// 2: {
// [[Class]]: "Object"
// }
// ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment