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.

Revisions

  1. jitensachdeva created this gist Jul 23, 2014.
    22 changes: 22 additions & 0 deletions iterator.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    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);
    }
    )