Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
¿Operación de asignación de desempaquetado de objetos?

¿Hay algo como esto en JavaScript? Básicamente, estoy buscando algo a lo largo de estas líneas:

 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}

¿Existe una sintaxis integrada para algo así, o es lo mejor que obtendré en ES6?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Object.assign haría.

 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 Report

0

No creo que exista tal sintaxis, pero si necesita usar mucho algo así, podría parchear la clase Object con una función de utilidad para ello:

 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 Report

0

Otra opción es usar Object.assign , no es un operador, pero hace el trabajo:

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!