I am unable to use this.concat(array)
inside an custom Array.prototype.extend
function created using Object.defineProperty
.
function clear(start, end) {
this.splice((!!start) ? start : 0, (!!end) ? end : this.length);
}
function extend(iterable, index) {
let a = [...this];
this.clear();
// this.length = 0;
// this.concat() does not work
this.concat([...a.splice(0, index), ...iterable, ...a]);
}
Object.defineProperty(Array.prototype, 'clear', { value: clear, enumerable: true, });
Object.defineProperty(Array.prototype, 'extend', { value: extend, enumerable: true, });
let a = [1, 2, 3, 4, 5, 6, 7, 8, 9];
let b = [1, 2, 3, 4, 5, [1, 2, 3], 6, 7, [1, 2, 3, 4, [1, 2, 3], 5, 6], 8, [1, 2, [1, 2, [1, 2, 3], 3, 4, 5], 3, 4, 5], 9];
let e = [...a];
console.log("extend :", e.extend(b, 3));
console.log("result", e);