Created
July 23, 2014 07:49
-
-
Save jitensachdeva/697b338f8b89a3952b83 to your computer and use it in GitHub Desktop.
Implementation of each on iterator in javascript
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
| var Iterator = function (values) { | |
| this.values = values; | |
| } | |
| Iterator.prototype = { | |
| each : function (block) { | |
| for (var i = 0; i < this.values.length; i++) { | |
| block(this.values[i]); | |
| } | |
| } | |
| } | |
| var iterator = new Iterator([1, | |
| 2, | |
| 3]) | |
| iterator.each(function(value) { | |
| console.log(value); | |
| } | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment