Javascript ES6 - Objects | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Javascript ES6 - Objects

El uso de assign () para crear un objeto duplicado, ¿Cuando se denomina Objeto base y cuando Objeto original?, O es lo mismo?

19th Aug 2020, 7:02 PM
Jesamine Marisela Ramon Yora
Jesamine Marisela Ramon Yora - avatar
5 Answers
0
I don't know much about js. But so I don't understanding what do you mean by base, original here.. Here, in let newStudent = Object.assign ({}, person, student); The person, student are source object which are copied or merged with target object, here {} is work as empty anonymous object initially... And finally result is assigned to new object newStudent : Then newStudent = { name: 'Jack', age: 18, sex: 'male' nombre: 'Bob', edad: 20, xp: '2' }; So basically happens like target({}) merged with person, then merged with student so finally student values are overridden by previous values of target. Syntax is like this : TargetObj = Object.assign( Target, sourceobj1, source2obj, source2obj,...., sourceobjN); Check values of objects changed after this operation by JSON.stringify(obj); for individual object properties.. Hope it helps you..
25th Aug 2020, 7:02 PM
Jayakrishna 🇮🇳
+ 1
if you wrote that then your more advanced than I I'm, but I'll do some research on the topic😄, thanks for posting otherwise I would have not know they existed.
23rd Sep 2020, 10:01 AM
Jack Murimi Kavita
Jack Murimi Kavita - avatar
0
Información no clara. ¿Hay ejemplos de código, por favor? ¿A qué idioma te refieres? Etiqueta el idioma por favor ... Not clear information.. Is any code examples please? Which language you meant? Tag the language please...
19th Aug 2020, 7:06 PM
Jayakrishna 🇮🇳
0
el ejemplo de: emplet person = { name: 'Jack', age: 18, sex: 'male' }; let estudiante = { nombre: 'Bob', edad: 20, xp: '2' }; let newStudent = Object.assign ({}, persona, estudiante); hace uso de Objeto.Assign(), y crer un nuevo Objeto. Mi duda es ¿Cuando es Objeto base y cuando Objeto original?
24th Aug 2020, 8:18 PM
Jesamine Marisela Ramon Yora
Jesamine Marisela Ramon Yora - avatar
0
No sé mucho sobre js. Pero entonces no entiendo qué quieres decir con base, original aquí ... Aquí en let newStudent = Object.assign ({}, persona, estudiante); La persona, el estudiante son objetos de origen que se copian o combinan con el objeto de destino, aquí {} se trabaja como un objeto anónimo vacío inicialmente ... Y finalmente el resultado se asigna al nuevo objeto newStudent: Luego newStudent = { name: 'Jack', age: 18, sex: 'male' nombre: 'Bob', edad: 20, xp: '2' }; Así que básicamente sucede como target ({}) combinado con person, luego combinado con student, por lo que finalmente los valores de los estudiantes son anulados por los valores previos de target. La sintaxis es así: TargetObj = Object.assign (Destino, sourceobj1, source2obj, source2obj, ...., sourceobjN); Compruebe los valores de los objetos cambiados después de esta operación por JSON.stringify (obj); para propiedades de objetos individuales. Espero que te ayude ...
25th Aug 2020, 7:03 PM
Jayakrishna 🇮🇳