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

127
Views
How can I call same-level method in base class?

This is the code I have

class Parent {
  async A(part, id) {
  }

  async B(part, id) {
    await this.A(part, id)
  }
}

class Child extends Parent {
  async A(id) {
  }

  async B(id) {
    await super.B("part1", id);
    // ...
  }
}

// let's assume I'm in async context
const child = new Child();
await child.B();

So what is happening here is the Child.B is calling Parent.B, and Parent.B is calling Child.A (which is expected).

I want to know if there is a way for me to call Parent.B > Parent.A.

I realize that perhaps I need to rename the methods, but I wanted to know if there is a way for this.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you want to call a method of a specific class instead of looking it up on the instance (on this) or your own prototype (trough super), reference that method directly and .call it on the instance:

class Parent {
  async A(part, id) {
  }

  async B(part, id) {
    await Parent.prototype.A.call(this, part, id)
  }
}
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!