array like objects code example

Example: javascript array-like object

function Arraylike(... args) {
    this.xarg = args;
    this.slice = function(num) {
        return new Arraylike(...this.xarg.slice(num));
    };
    this.splice = function(... args) {
        console.error("Splice is not implemented for now.");
    };
    this.toArray = function() {
        return this.xarg;
    };
    this.length = this.xarg.length;
    for(let i = 0; i < this.xarg.length; i++) {
        this[i] = this.xarg[i];
    }
}



Array.prototype.toArraylike = function() {
    return new Arraylike(...this);
};


let yourobject = new Arraylike("whatever", "goes", "here");