Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

124
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda