I have a simple ES6 class, like so:
class Ring extends Array {
insert (item, index) {
this.splice(index, 0, item);
return this;
}
}
Basically it is
class ProxyRing extends Array {
constructor(...args) {
super(...args)
return new Proxy(this, {
get: function (target, name) {
var len = target.length;
if (typeof name === 'string' && /^-?\d+$/.test(name))
return target[(name % len + len) % len];
return target[name];
}
});
}
insert (item, index) {
this.splice(index, 0, item);
return this;
}
}