Javascript ES6 - Objects | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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 Respostas
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 šŸ‡®šŸ‡³