Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

100
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!