I have a class that is extended by many other classes.
I pass data to through an instances of these classes and they seem to call a 'this' property of the main class and each of them are able to do it, does this mean they have their own 'copy' of this value?
I really want to understand how this all works, how is data passed through the classes and used specifically on each one, Il show the code:
The parent class (just a relevant section of it):
export abstract class EngagementGraphNode {
public endpoint: string;
public id: string;
public name: string;
public x?: number;
public y?: number;
public parent?: EngagementGraphNode;
public children: EngagementGraphNode[] = [];
}
Then I have a class which access some of the properties such as this.children:
export class EngagementProduct extends EngagementGraphNode {
public engagements: Engagement[] = [];
public description: string;
public timelineRows: TimelineRow[] = [];
setProperties(json: IEngagementGraphNode, placeholder: string, color: string) {
}
setChildren(filters: IFilterParams, rebuild: boolean): void {
let list = [];
this.engagements.forEach(engagement => {
const item = this.find(engagement, filters, rebuild);
if (this.matchFilters(engagement, filters) && item) { list.push(item) }
});
this.children = list;
}
Then there are several other classes which also use 'this.children'
I think that each this.children relates to the single variable and ultimate value that is contained within the parent class, which means that each class must be being called at separate times for this to work? as it does work.
Could someone explain that if possible please?
Also It looks like the classes call on eachother to send data when the app is first loaded so the data is 'parsed' through - is this what is happening? Perhaps I need to read some computer science books and understand the nitty gritty of whats going on with how classes are called, their sequences and how the data is assigned to instances and how that works.