Created
September 22, 2020 03:54
-
-
Save bsdelf/e30a54657f8e70f9a8e617f43434430c to your computer and use it in GitHub Desktop.
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
class Range { | |
constructor(from, to, step = 1) { | |
this.value = from; | |
this.to = to; | |
this.step = step; | |
} | |
next() { | |
if (this.value > this.to) { | |
return { value: undefined, done: true }; | |
} | |
const value = this.value; | |
this.value = value + this.step; | |
return { value, done: false }; | |
} | |
[Symbol.iterator]() { | |
return this; | |
} | |
} | |
for (const data of new Range(3, 4)) { | |
console.log(data); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment