Не думаю, что красиво, но рабочий вариант
class Cupboard {
constructor(props) {
this._fromParent = { ...props };
}
delete() {
console.log(this._fromParent);
}
refreshProps(props) {
this._fromParent = { ...props }
}
//...
}
class Room {
constructor() {
this._number = 5;
this._price = 500;
this.cupboard = new Cupboard(this);
}
get number() {
return this._number;
}
set number(value) {
this._number = value;
this.cupboard.refreshProps(this);
}
}
const room = new Room();
room.cupboard.delete();
//{_number: 5, _price: 500}
room.number = 6
room.cupboard.delete()
//{_number: 6, _price: 500, cupboard: Cupboard}
Можно придумать через паттерн observable