I have two class Test0 and Test1, the both classes are inherited from Array. For Test0 I use ES6 syntax, for Test1 ES5.
class Test0 extends Array {
constructor(...args) {
super(...args)
this.test = 'this is my array'
}
}
function Test1(...args) {
Array.call(this, ...args)
}
// Test1.prototype = Object.create(Array.prototype)
Object.setPrototypeOf(Test1.prototype, Array.prototype)
Object.setPrototypeOf(Test1, Array)
Test1.prototype.constructor = Test1
const a = new Test0(1, 2)
const b = new Test1(1, 2)
console.dir(a, b)
For Test0 I get the expected result: Test0(2) [ 1, 2 ]
, but for Test1 I get :Test1 {}
.
Why is this happening? How can I get a result like in ES6 using ES5?