I\'m trying to extend Array so that I can add in my own additional functionality. I\'ve read that extending Array.prototype can be dangerous, so I am trying to do it the correct
You used the spread operator on the wrong place. https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Operators/Spread_operator
I guess you would like to reach more parameters into the constructor function.
class Array2 extends Array {
constructor(items) {
super(items); //here is the problem
}
addOne() {
return this.map( (x) => {
return x+1;
} );
}
}
let arry2 = Array2.from([2, 1, 4, 22]).addOne();
console.log("arry2", arry2);