我尝试从Array
继承,但是instanceof
无法正常工作。
class MyList<T> extends Array<T> {}
const l = new MyList<string>()
console.log(l instanceof MyList) // false <- WRONG
console.log(l instanceof Array) // true
答案 0 :(得分:0)
感谢@jcalz,代码应如下php mysqli_connect: authentication method unknown to the client [caching_sha2_password]
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