Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

103
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda