class Wheel{
constructor(num) {
this.num = num;
}
num:0,
roll(){
console.log('wheel is rolling!');
}
}
class Car{
constructor(engine, wheel) {
this.engine = engine;
this.wheel = wheel;
}
engine:0,
wheel,
}
let wheel = new Wheel(4);
let car = new Car(1, wheel);
car.wheel.roll();
wheel对象是car对象的属性,怎么对car和wheel进行解耦,有时候属性对象的属性又是父对象,例如为wheel添加belong属性,表示所属的car,请问一般怎么进行解耦?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…