Giving a Corvette a supercharger—Implements versus Extends

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.

Getting ready

Create a canvas to display some output.

<h1>Speed Indexes:</h1>
<div id="mycanvas"></div>

How to do it...

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 ...

Get MooTools 1.3 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.