I have an outer class export class
as a template for an object.
export class Car{
name: Boolean;
other: {
prize: String;
brand: String;
};
doors: {
number: String,
size: String,
};
}
I'm trying to access it from another class, so I've created a new variable
var car= new Car();
Since name
it is a boolean
, I assume that it is initialized with a true
position which is its default value. My problem comes when I try to initialize the object doors
after it doesn't have it.
var car= new Car();
this.car.doors[pos].number;
When I try to access it it tells me that undefined
. How could I access it? I guess I need to initialize it in the constructor.
I don't need to initializeother
You must initialize it in its constructor if you want to access its attributes, since it is an "Own Object" , here is an alternative:
The variables inside
Other
andDoors
, are going to beundefined
if you try to access them, since no value is assigned to them.