我有一个这样的对象
this.currentRegion = {
latitude: 25.3170013,
longitude: 55.4748285,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA,
};
和另一个对象
coords = {
accuracy: 20,
altitude: 5,
heading: 0,
latitude: 25.380599999999998,
longitude: 55.3992,
speed: 0,
}
我需要
this.currentRegion = {
latitude: 25.380599999999998,
longitude: 55.3992,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA,
}
我尝试了this.currentRegion = Object.assign(this.currentRegion,region.coords);
并得到了错误
Attempting to set key on an object that is immutable and has been frozen
最佳答案
this.currentRegion = {...this.currentRegion, latitude: coords.latitude, longitude: coords.longitude}
关于javascript - 将一个对象分配给另一个不带所有字段的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57556480/