I tried to inherit from Array, but the instanceof not working.
class MyList<T> extends Array<T> {}
const l = new MyList<string>()
console.log(l instanceof MyList) // false <- WRONG
console.log(l instanceof Array) // true
I tried to inherit from Array, but the instanceof not working.
class MyList<T> extends Array<T> {}
const l = new MyList<string>()
console.log(l instanceof MyList) // false <- WRONG
console.log(l instanceof Array) // true
Thanks to @jcalz the code should be as below, more details
class MyList<T> extends Array<T> {
constructor() {
super()
Object.setPrototypeOf(this, MyList.prototype)
}
}
const l = new MyList<string>()
console.log(l instanceof MyList) // false <- WRONG
console.log(l instanceof Array) // true