Class definition and Constructor:
Inherit base functionality from Gauge class:
This type of inheritance is called Prototypal Inheritance. Under the hood, it’s different from classical class based inheritance. But, should be very familiar.
Methods (Do the work for the Speedometer Class):
The accelerate method is only within the scope of the Speedometer class. So only instances of a Speedometer object or children of the Speedometer class have access to the method.
Using the Speedomter Class
Well, we so deliciously put together our Speedometer class. Now, it’s time to have some fun and use an instance of the Speedometer object. Let’s take this Teslar Roadster for a spin: