Created
November 19, 2020 23:39
-
-
Save cevaris/31d773dbf7e0215c98692ec40d28ca99 to your computer and use it in GitHub Desktop.
custom Prototype iterator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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