ES6 對象的擴展運算符(...)用於取出參數對象的所有可遍歷屬性,拷貝到當前對象之中

setInitialState({ ...initialState, currentUser: undefined });
...initialState = {currentUser: {}, fetchUserInfo: {}, settings: {}}
setInitialState({currentUser: {}, fetchUserInfo: {}, settings: {}, currentUser: undefined })
setInitialState({currentUser: undefined, fetchUserInfo: {}, settings: {}})

使用擴展運算符合並對象:

const obj1={
    name1:"cyy1",
    age1:18
}
const obj2={
    name2:"cyy2",
    age2:28
}
const obj3={
    name3:"cyy3",
    age3:38
}
const obj={
    name:"cyy",
    ...obj1,
    ...obj2,
    ...obj3
}

  

 

https://www.cnblogs.com/chenyingying0/p/12562648.html

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章