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

96
Visualizações
How to update parent class property so it would be available for existing child class instances

I have a multiple instances of the classes that have the same parent class. And for specific case it is required to update parent class property so all available instances of the child classes would access updated property.

I can reach it with prototype in case if class property doesn't exist already:

class Foo {
    someVal = 'Hello'
}

class Bar extends Foo {

}

let inst = new Bar()
Foo.prototype.someNewValue = 'Hello World'
console.log(inst.someNewValue) //Hello World

But in my case I need to update an already existing property:

class Foo {
    someVal = 'Hello'
}

class Bar extends Foo {

}

let inst = new Bar()
Foo.prototype.someVal= 'Hello World'
console.log(inst.someVal) //Still output "Hello" because existing property value has a more priority than a value from prototype. While "Hello World" is desirable
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

With the prototype, you can not overwrite and change the property of class, but you can set the new property to the class try this:

  class Foo {}
    
  class Bar extends Foo {}
    
  let inst = new Bar();
  Foo.prototype.someVal = "Hello World";
  console.log(inst.someVal);
  //hello world
about 4 years ago · Juan Pablo Isaza Relatório
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