yahoo/mojito — pull request #1385 by aljimenez (2014-06-27 20:01:45+00:00)
Title: Allow mojits to be extended

This pull request allows mojits to be easily extended by other mojits. For example:

mojits/Vehicle/controller.server.js

```js
YUI.add('VehicleController', function (Y, NAME) {
var Vehicle = function () {
this.type = 'Vehicle';
this.transmission = 'automatic';
};

Y.namespace('mojito.controllers')[NAME] = Vehicle;
Y.extend(Vehicle, Y.Base, {
index: function () {
ac.done(ac.params.body('brand') + ' ' + this.getType());
},
getType: function () {
return this.type;
}
});
}, '0.0.1', {
requires: {
'oop',
'mojito-params-addon'
}
});
```

mojits/Motorcycle/controller.server.js

```js
YUI.add('MotorcycleController', function (Y, NAME) {
var Vehicle = Y.mojito.controllers.VehicleController,
Motorcycle = function () {
Motorcycle.superclass.constructor.call(this);
this.type = 'Motorcycle';
this.transmission = 'manual';
};

Y.namespace('mojito.controllers')[NAME] = Motorcycle;
Y.extend(Motorcycle, Vehicle);
}, '0.0.1', {
requires: {
'VehicleController'
}
});
```

In this example, the Motorcycle mojit extends the Vehicle mojit, which extends the Y.Base class. Notice that the controllers can be defined as a function; this allows mojits to extend using Y.extend, which ensures that the prototype chain is maintained regardless of how many levels of extensions. Also notice that the Motorcycle controller does not have to re-specify the 'mojito-params-addon' requirement; it just has to specify the Vehicle controller requirement, and its addon will automatically include any addon required by Vehicle controller.

To ensure that mojit dependencies work with resourceStore > lazyMojits on, mojits depending on other mojits should specify their dependencies in defaults.json:

mojits/Motorcycle/defaults.json
```js
[{
"settings": [ "master" ],
"dependencies": [ "Vehicle" ]
}]
```