I found a very weird behavior, I'm using Firefox 93.0 64 bits, lets pick the next example:
class SubArray extends Array{
constructor(...i){
super(...i)
}
}
The intuitive behavior, is that this new class should do the same as a normal array, with all their properties, but does not do that, we get the next in the console.
a=new SubArray([1, 2, 3])
a[0]
Array(3) [ 1, 2, 3 ]
We are not getting the first element....
How can we extends a class to array, and appropriately inherit properties? (all of them, set elements, get elements, etc, etc)
Thx,
as @Barmar says.
This will works if we do new SubArray(1, 2, 3, 4), this is because there is a difference betwen the builtin classes and the user classes, in the builtin classes we use [1, 2, 3], we are not using the normal user constructor, so the equivalence would be new Array(1, 2, 3).
Just to keep in mind, if we are using builtin classes from JS, we need to check how JS translate the usual form like [] to the usual constructor, other example would be, how {1: 'hi'} is translated to the Object constructor?, just keep in mind this question.