I need an kind of "circular array". I have everything working but for single instance. I don't know how to make it "instantiable". I mean I want it to work the following way:
var arr = ['a', 'b', 'c', 'd']; // it's kind of pseudo-code
arr.getNext(); // gives a
arr.getNext(); // gives b
arr.getNext(); // gives c
arr.getNext(); // gives d
arr.getNext(); // gives a
arr.getNext(); // gives b
// and so on
I know I can create object with array inside and iterate over it, but I'm pretty sure I can do this the other way.
The problem is I need several instances of that object. If it was only one instance I could do:
var arr = ['a', 'b', 'c', 'd'];
arr.getNext = function() {
// ... I got this stuff working
}
How to allow createion of several instances of such custom arrays?