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

125
Vistas
Possible to assign function parameter via destructuring?

Is it possible to do something like the following in js?

function Something( Point{PointX, PointY}   ) {
    console.log('Point', Point);
    console.log('PointX,PointY', PointX, PointY);
}
Something([1,2]);

If so, what would be the proper way to do that?

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

0

function Something(Point) {
  const [PointX, PointY] = Point
  console.log('Point', Point)
  console.log('PointX,PointY', PointX, PointY)
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

Is this what you need?

function Something([PointX, PointY]) {
    console.log('PointX,PointY', PointX, PointY);
}

You can destructure both arrays (function([x, y]) and objects (function({ x, y })).

about 4 years ago · Juan Pablo Isaza Denunciar

0

Sure, but make sure the keys match up to do the destructuring assignment for an object, such as:

function Something({x,y}) {
    console.log('PointX, PointY', x, y);
}
Something({x: 1, y: 2});

In terms on naming and also assigning it to the outer object, perhaps you can do something like this instead:

function Something(Point) {
    const {x,y} = Point;
    console.log('Point, PointX, PointY', Point, x, y);
}
Something({x: 1, y: 2});

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