使用结构赋值替代Object.assign部分使用场景
let state = {
name: 123,
createTime: '2018-08-08',
color: '#233'
};
let newState = {
do: 'read book',
like: '2333'
};
// 在react中会用到类似的用法
// let res = Object.assign({},state,newState);
// 现在直接
let res = { ...state, ...newState};
console.log(res);
// {name: 123, createTime: "2018-08-08", color: "#233", do: "read book", like: "2333"}
网友评论