Created
March 23, 2013 05:48
-
-
Save satoshun/5226623 to your computer and use it in GitHub Desktop.
test iterator
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
describe('iterator', function() { | |
it('test', function() { | |
var Iter = function(data){ | |
this.index = 0; | |
this.data = data; | |
}; | |
Iter.prototype = { | |
next: function(){ | |
var elem = this.data[this.index]; | |
this.index += 1; | |
return elem; | |
}, | |
hasNext: function(){ | |
return this.index < this.data.length; | |
}, | |
seek: function(reindex){ | |
this.index = reindex; | |
} | |
}; | |
var data = [1, 2, 3, 4, 5]; | |
var iter = new Iter(data); | |
while(iter.hasNext()){ | |
console.log(iter.next()); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment