Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

104
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda