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

114
Visualizações
Object unpacking assignment operation?

Is there anything like this in JavaScript? Basically, I'm looking for something along these lines:

let obj_a = {test: "one", property: "two"};
let obj_b = {test: "1", other: "three"};
let obj_b ...= obj_a; // would be the equivalent of obj_b = {...obj_b, ...obj_a}

Is there builtin syntax for something like that, or is this the best I'm going to get in ES6?

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Object.assign would do.

let obj_a = { test: "one", property: "two" },
    obj_b = { test: "1", other: "three" };

Object.assign(obj_b, obj_a);

console.log(obj_b);

about 4 years ago · Juan Pablo Isaza Relatório

0

I don't think any such syntax exists, but if you need to use something like that a lot, you could monkey-patch the Object class with a utility function for it:

Object.prototype.merge = function(x) { Object.assign(this, x) }
let obj_a = {test: "one", property: "two"};
obj_a.merge({test: "1", other: "three"});
console.log(obj_a);

about 4 years ago · Juan Pablo Isaza Relatório

0

An other option is to use Object.assign it's not an operator but it get's the job done:

Object.assign(obj_b, obj_a)
// {test: 'one', other: 'three', property: 'two'}

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign

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