Using .splice method in subclass of Array in javascript?
问题 I am trying to create a subclass of javascript's Array. I want to initiate subclass with array-type argument and add a method to remove an element from the array (subclass). My code looks like this: class CustomArray extends Array { constructor(array) { console.log('Initiating array:', array) super(...array); } remove(element) { let index = this.indexOf(element); if (index > -1) { return this.splice(index, 1); } return []; } } var a = ['a', 'b', 'c', 'd', 'e']; var list = new CustomArray(a)