我有以下三个课程。我有最顶层的Workout类,其中包含Exercise类的实例,而该类本身包含Set类的实例。
当我们沿着对象的层次结构向下移动时,设置的对象如何在不传递包含顶层对象的引用的情况下访问“锻炼/锻炼”对象的属性和方法?
class Set {
constructor(name) {
this.name = name;
}
get name() {
return this.name;
}
listParentObjectProperties() {
//output Workout object properties
//output Exercise objet properties
}
}
class Exercise {
constructor(name) {
this.name = name;
}
get name() {
return this.name;
}
get sets() {
return [
new Set("Set 1"),
new Set("Set 2"),
new Set("Set 3"),
]
}
}
class Workout {
constructor(name) {
this.name = name;
}
get name() {
return this.name;
}
get Exercises() {
return [
new Exercise("Barbell Squat"),
new Exercise("Barbell Bench Press")
]
}
}
let sampleWorkout = new Workout("Sample Workout 1");
sampleWorkout.Exercises[0].sets[0].listParentObjectProperties();