Estoy tratando de usar la función de map dentro de toString sobrescrita en mi subclase Array y veo un comportamiento extraño. Parece que .map está llamando al constructor de mi subclase sin motivo aparente y arrojando un TypeError .
class Seq extends Array { constructor(seq = '') { super(); (seq.match(/.{2}/g) || []).forEach((mi) => this.push(mi)); } toString() { return this.map(it=>it).join(''); } } new Seq('1643').toString() //expects to see '1643' as the output but getting a TypeError Recrear la matriz en el método toString soluciona el problema, pero me gustaría entender por qué.
toString() { return [...this].map(it=>it).join(''); }