Recently, I've come across an issue in my code while working with custom objects and arrays of them. I have identified a scenario where the push() method works fine and another where it doesn't.
Scenario 1 (working as expected):
class MyObject{
private reference: d3.Selection<SVGElement>;
public constructor(ref: d3.Selection<SVGElement>){
this.reference = ref;
}
}
interface ViewModel{
objects: MyObject[]
}
class MyApp{
private root: d3.Selection<SVGElement>
private viewModel: ViewModel;
constructor(options: Type){
this.root = options.root
this.viewModel.objects.push(new MyObject(this.root))
}
}
Scenario 2 (not functioning properly):
class MyObject{
private reference: d3.Selection<SVGElement>;
public constructor(ref: d3.Selection<SVGElement>){
this.reference = ref;
}
}
class MyApp{
private root: d3.Selection<SVGElement>
private objects: MyObject[];
constructor(options: Type){
this.root = options.root
this.objects.push(new MyObject(this.root)) //seems to freeze the whole program
}
}
Could you please point out what I might be doing wrong? Any assistance would be highly appreciated.
Michal