I create a custom list-like object that contains multiple pc.Vec2 objects.

The purpose of this object is to confines the newly created vector objects to a limited number.

The problem was that I tried to derive the list object for pc.Vec3 from the 2-dimensional vector array object, but couldn’t figure out the wise and keen approach.

```
/* Custom Constant Functions */
// Create a 2 Dimensional Vector Array
pc.Vec2Array = function ( _length ) {
let _vectors = [];
for (var i = 0; i < _length; i++) {
_vectors.push(new pc.Vec2(0, 0));
}
this.vectors = _vectors;
this.x = [];
this.y = [];
this.lengths = [];
this.update = function () {
let _Xarray = [];
let _Yarray = [];
let _vectorLengths = [];
_vectors.forEach(function(moment) {
_Xarray.push(moment.x);
_Yarray.push(moment.y);
_vectorLengths.push(moment.length());
});
this.x = _Xarray;
this.y = _Yarray;
this.lengths = _vectorLengths;
};
this.push = function ( x, y ) {
for (let i = _length-1; i > 0; i--) {
this.vectors[i].copy( this.vectors[i-1] );
}
this.vectors[0].set( x, y );
this.update();
};
this.update();
};
// Create a 3 Dimensional Vector Array
pc.Vec3Array = function ( _length ) {
let _vectors = [];
for (var i = 0; i < _length; i++) {
_vectors.push(new pc.Vec3(0, 0));
}
this.vectors = _vectors;
this.x = [];
this.y = [];
this.z = [];
this.lengths = [];
this.update = function () {
let _Xarray = [];
let _Yarray = [];
let _Zarray = [];
let _vectorLengths = [];
_vectors.forEach(function(moment) {
_Xarray.push(moment.x);
_Yarray.push(moment.y);
_Zarray.push(moment.z);
_vectorLengths.push(moment.length());
});
this.x = _Xarray;
this.y = _Yarray;
this.z = _Yarray;
this.lengths = _vectorLengths;
};
this.push = function ( x, y, z ) {
for (let i = _length-1; i > 0; i--) {
this.vectors[i].copy( this.vectors[i-1] );
}
this.vectors[0].set( x, y, z );
this.update();
};
this.update();
};
```

As you can see, there are obvious parts in the code for pc.Vec3Array that are identical to the parts in the Vector 2 Array object.

I attempt to use a funtion.prototype.call, but if anyone knows the better solution for this code, please guide me. Or, if anyone has a point to criticize the fundamental of this code that disrupts the recommended standard practice, feel free to comment on this post.

https://playcanvas.com/project/732663/overview/Mound%20Simulator