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 way with class inheritance.
The issue I'm running into is that map is undefined. I can obviously work around this but I don't understand why as I am extending Array and therefore should have It's functionality?
export default class Array2 extends Array {
constructor(items) {
super(...items);
}
addOne() {
return this.map((x)=>{
return x+1;
})
}
}
let arry2 = new Array2 ([9, 1, 4, 0]).addOne();
console.log(arry2);
I expect to have Array2 (4) [10, 2, 5, 1] logged into the console but instead i get the following error thrown.
Uncaught TypeError: undefined is not a function
Edit Removing the constructor seems to fix the issue but does not explain why it fails when a constructor is present. especially when the constructor is just calling super.
publickeyword before theaddOne()definition change anything?mapfunction fails... Proof