Be ready to watch for several things in this recipe. Firstly, note how the extended corvette methods can use this.parent
. Secondly, note how the implemented corvette, the ZR1, can implement multiple classes.
Create a canvas to display some output.
<h1>Speed Indexes:</h1> <div id="mycanvas"></div>
Here we create a class to represent a car. This car does not have an engine until it goes through further steps of manufacturing, so if we ask what its speed is, the output is zero. Next, we create a class to represent a sporty engine, which has an arbitrary speed index of 10.
// create two classes from the base Class var Car = new Class({ showSpeed: function() { return 0; } }); var SportyEngine = new Class({ speed: 10 });
Now we get to work. First, we begin by manufacturing corvettes, a process which is the extension of Car
, they are faster than an empty chassis, of course, so we have them...