Upgrading all Corvettes via recall—Implement AND Extend in unison!

But wait, we can do even more with Implements and Extends! Prepare to see them used simultaneously.

Getting ready

Starting off from where our last recipe left off will get us ready.

<h1>Speeds Before</h1>
<div id="before"></div>
<h1>Speeds After</h1>
<div id="after"></div>
// create two classes from the base Class
var Car = new Class({
showSpeed: function() { return 0; }
});
var SportyEngine = new Class({
speed: 10,
showSpeed: function() { return this.speed; }
});
// Extend one, Implement the other
var Corvette = new Class({
Extends: Car,
speed: 1,
showSpeed: function() {
// this.parent calls the overridden class
return this.parent()+1;
}
});

How to do it...

In this example, we want ...

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.