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

102
Views
Multi-level object inheritance in JavaScript with `super` keyword

I want to compose multiple objects into one. The super keyword should call corresponding parent object method. If parent's method is not present, it should call next parent's method and so on.

Example code that throws:

var base = {
  runBusinessLogic() {
    console.log('BASE');
  }
}

var concrete = {

  unrelatedExtraMethod() {
  }
}

var addon = {
  runBusinessLogic() {
    super.runBusinessLogic(); // I expect this super call to call base.runBusinessLogic(..)
    console.log('ADDON');
  }
}

var layer2 = Object.setPrototypeOf(concrete, base);
var layer3 = Object.create(layer2, addon);

layer3.runBusinessLogic(); // throws "TypeError: layer3.runBusinessLogic is not a function"

I expect the layer3.runBusinessLogic(..) to call base.runBusinessLogic(..) and still have callable unrelatedExtraMethod on itself.

How to make the super keyword work as outlined?

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

0

    var base = {
      runBusinessLogic() {
        console.log('BASE');
      }
    }

    var concrete = {

      unrelatedExtraMethod() {
      }
    }

    var addon = {
      runBusinessLogic() {
        super.runBusinessLogic(); // I expect this super call to call base.runBusinessLogic(..)
        console.log('ADDON');
      }
    }

    var layer2 = Object.setPrototypeOf(concrete, base);
    var layer3 = Object.setPrototypeOf(addon, layer2); // change this

    layer3.runBusinessLogic()

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!