I currently am taking an online javascript course and it says that Object.property.property is a valid variable, but I cannot for the life of me find anything on the internet about it or make it work in my program. In the notes for this section, it says its possible to make a property of an object have a sub property. Here is the code that the example is referring to:
function car () {
this.weight=0;
this.engine="";
this.aero_factor=0;
this.speed=0;
}
var porsche = new car()
The examples it gives when saying that "Properties can be Objects, too" are:
car.interiorStyle=”Type 12”;
car.interiorStyle.upholstery=”Leather”;
car.interiorStyle.airConditioning=true;
car.interiorStyle.radio=”JVC”;
car.interiorStyle.radio.power=200;
But that's it. It doesn't say how to implement it at all and I can't figure out why when I do it, it ends up as undefined every time.
Here is my code:
function Car(weight, speed, turboSpeed) {
this.weight=weight;
this.speed=speed;
this.speed.turbo = turboSpeed;
}
var porsche = new Car(1750, 125, 250);
alert(porsche.weight); //1750
alert(porsche.speed); //125
alert(porsche.speed.turbo); //undefined
If I could get some help with this that would be great. Thanks!