Object Spread - Supercharged

preview_player
Показать описание
Surma shows you the new Object Spread operator “...” in JavaScript.

Рекомендации по теме
Комментарии
Автор

Very handy for Redux reducers because it is immutable... using it all the time, loving it immensely

LarsRyeJeppesen
Автор

I didn't think about it like that. Thanks!

durchschnittlich
Автор

1. How does the object spread differ from Object.assign({}, obj1, obj2)
2. Does it do 'deep copying' or are the non-primitive values related back to their source object?
3. Is it like Obj.assign in that any duplicated properties will be overwritten by the right-most object?

r-i-ch
Автор

this ellipsis "..." symbol before variables are present in other contexts too: funcion definitions, object creations and array creations; but people are starting to give them different names. i always thought of the "..." as the "spread operator"

function foo( ...args ) { /* "args" will be an array but the good old "arguments" is present too */ }

object2 = { ...object1, ...array1, other_variable, key: 'value' } // mixing arrays and objects (eew)

array2 = [...array3, 2, 3, 4] // cant mix objects here (phew)

dandan
Автор

does this work like Object.assign(a, b)?
is the newly created object "both", a new Object or will changing "a.a1"affect "both.a1"

chris-eg
Автор

Would this be able to work with object destructuring? E.g. in the parameter instead of reassigning on the parameter on a new line

Jeremybelleu
Автор

Isn't it bad practice to reassign function arguments, especially if it is object?

talgatsaribayev
Автор

This isn’t supported yet in Edge or Safari

MrMcCoyD