Created
March 15, 2018 17:58
-
-
Save gsathya/59c51fc5d432c8592431a608f27fffef 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
Object.defineProperty(Number.prototype,Symbol.iterator,{ | |
*value({ start = 0, step = 1 } = {}) { | |
var inc = this > 0 ? step : -step; | |
for (let i = start; Math.abs(i) <= Math.abs(this); i += inc) { | |
yield i; | |
} | |
}, | |
enumerable: false, | |
writable: true, | |
configurable: true | |
}); | |
for (let i of [...8]) { | |
console.log(i); | |
} | |
// Or even just: | |
for (let i of 8) { | |
console.log(i); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment