Skip to content

Instantly share code, notes, and snippets.

@cevaris
Created November 19, 2020 23:39
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 cevaris/31d773dbf7e0215c98692ec40d28ca99 to your computer and use it in GitHub Desktop.
Save cevaris/31d773dbf7e0215c98692ec40d28ca99 to your computer and use it in GitHub Desktop.
custom Prototype iterator
function Data() {
this.data = [1, 2, 3, 4, 5];
}
Data.prototype[Symbol.iterator] = function* () {
for (const e of this.data) {
yield e;
}
};
const data = new Data();
for (const e of data) {
console.log(e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment