I'm not a big fan of Object.assign, in my opinion, it is hard to read and not elegant, I try to avoid it. Somewhere I saw this in redux reducer
case ADD_TODO:
return Object.assign({}, state, {
todos: [
...state.todos,
{
text: action.text
}
]
})
Just curious is Object assign looks good above? Why not just do this instead?
case ADD_TODO:
return {
...state,
todos: [
...state.todos,
{
text: action.text
}
]
}
Why not just do this instead?
Because it's not valid ES6 anymore.
The object rest/spread syntax proposal had been around for some time but only was accepted for ES2018. See here for details.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.