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

119
Visualizações
JavaScript copy a class atributes and create a new identical object

I have a class that copy objects and it looks like this:

Class CoppyComponent {
    constructor(element) {
        return Object.assgin(Object.create(Object.getPrototypeOf(element)), element);
     }
}

I have another class to create HTML elements that use an array to keep track of the HTML elements created

Class Component {
    constructor(){
        this.arr = [];
    }
}

I use the classes this way:

const hi = new Component();
hi.CreateEl({ type: "h1", text: "Hello", parrent: ".a" });
hi.CreateEl({ type: "h2", text: "Hello", parrent: ".a" });
hi.CreateEl({ type: "h3", text: "Hello", parrent: ".a" });
hi.CreateEl({ type: "h4", text: "Hello", parrent: ".a" });
hi.CreateEl({ type: "h6", text: "Hello", parrent: ".a" });
const h1Copy = new CoppyComponent(hi);
`h1Copy.load(".b");`

createEl methid just create a new HTML element

load method just modify the parent element HTML elements go into div with class b only instead of both divs (a, b)

I console.log both objects (hi, h1Copy) and are identical What I think the problem is but I am not sure is that both objects share the same array.

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