Last active
September 23, 2015 15:38
-
-
Save kourge/577652 to your computer and use it in GitHub Desktop.
for (var i of (1).upto(5)) { ... }
This file contains 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
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