Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

101
Vistas
Strange toString behaviour when extending Array class

I'm trying to use the map function inside the toString overwritten in my Array subclass and I'm seeing a strange behaviour. It looks like that .map is calling the constructor of my subclass for no apparent reason and throwing a 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

Recreating the array in the toString method fixes the problem, but I'd like to understand why.

toString() {
    return [...this].map(it=>it).join('');
}
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda