There is a classic design pattern called "the mediator pattern" that is used in apps and popular game engines that will help you do this.
check this link below for a simple explanation and if you have any questions ask away
Mediator/Middleware Pattern[
^]
the parent has an array of children and when a child is created you pass the parent in the constructor. the child will be able to reference the parent and get its number.
class childsParent {
constructor(){
this.number = 69;
this.children = [];
}
getChild(childName){
const component = this.children.find(child=> child.name === childName);
if(component){
console.log(component);
} else {
console.log("child not found");
}
}
}
class parentsChild {
constructor(name, parent){
this.name = name;
this.parent = parent;
this.parent.children.push(this);
}
getParentsNumber(){
console.log(this.parent.number)
}
}
const newParent = new childsParent();
const child1 = new parentsChild("child1", newParent);
child1.getParentsNumber();