所以在我的陣營項目,我有一個後備的默認狀態,看起來像這樣的地址形式:使用每個等於null的鍵實例化對象的最佳方法?
state = {
newLocation: this.props.location || {
lat: null,
lng: null,
street: null,
complement: null,
neighbourhood: null,
city: null,
state: null,
zipCode: null,
country: null,
},
}
但是,這感覺挺可笑的定義與等於空的所有密鑰這麼大的天體。有沒有更簡單的方法來做到這一點?東西在ES6/ES7?
難道他們絕對需要明確設置爲'null'?不能使用這些屬性的任何代碼只接受'undefined'作爲一個空值,以便您可以:'newLocation:this.props.location || {}'。 – CodingIntrigue