Skip to content

Instantly share code, notes, and snippets.

@gsathya
Created March 15, 2018 17:58
Show Gist options
  • Save gsathya/59c51fc5d432c8592431a608f27fffef to your computer and use it in GitHub Desktop.
Save gsathya/59c51fc5d432c8592431a608f27fffef to your computer and use it in GitHub Desktop.
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