Created
December 16, 2016 21:28
-
-
Save Spencer-Easton/e9a24452876b6e5d4abe7560a8bf0820 to your computer and use it in GitHub Desktop.
A stupid simple Iterator Service
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
var IteratorService_ = function(array){ | |
var newArray = array.slice(0); | |
Object.defineProperty(newArray, 'nextIndex', { value: 0, enumerable: false, writable:true }); | |
Object.defineProperty(newArray, 'next', { value: function(){if(this.nextIndex >= this.length){throw new Error("NoSuchElementException")}else{return this[this.nextIndex++]}}, enumerable: false }); | |
Object.defineProperty(newArray, 'hasNext', { value: function(){return (this.nextIndex < this.length)}, enumerable: false }); | |
return newArray; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment