Skip to content

Instantly share code, notes, and snippets.

@kourge
Last active September 23, 2015 15:38
Show Gist options
  • Save kourge/577652 to your computer and use it in GitHub Desktop.
Save kourge/577652 to your computer and use it in GitHub Desktop.
for (var i of (1).upto(5)) { ... }
Number.prototype.upto = function upto(end) {
var start = this;
function NumberIterator() {
this.current = start;
}
NumberIterator.prototype.next = function next() {
if (this.current > end) {
throw StopIteration;
} else {
return this.current++;
}
};
return {__iterator__: function() { return new NumberIterator() }};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment