Skip to content

Instantly share code, notes, and snippets.

@jitensachdeva
Created July 23, 2014 07:49
Show Gist options
  • Save jitensachdeva/697b338f8b89a3952b83 to your computer and use it in GitHub Desktop.
Save jitensachdeva/697b338f8b89a3952b83 to your computer and use it in GitHub Desktop.
Implementation of each on iterator in javascript
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