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

135
Vistas
How to use an object as an argument in JavaScript subclasses?

For example, if I have something like this:

class X{
    constructor({one, two}){
        this.one = one 
        this.two = two
    }
}

class Y extends X{
    constructor(props, three){
        super(props)
        this.three = three
    }
}

And I want to create an object with:

console.log(new Y({one: 1, two: 2, three: 3}))

Is it possible? I tried other ways like:

console.log(new Y({one: 1, two: 2}, 3))
console.log(new Y({one: 1, two: 2}, {three: 3}))

but they are uncomfortable.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can do that...yes
just use the destructuring assignment

 class X { constructor({one, two}) { this.one = one this.two = two } displaying() { console.log(this) } } class Y extends X { constructor({three, ...OneTwo}) { super(OneTwo) this.three = three } } let zz = new Y({one: 1, two: 2, three: 3}) zz.displaying()

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