marionettejs/backbone.marionette — pull request #282 by jsoverson (2012-10-12 03:53:21+00:00)
Title: Evaluate "augment" implementation of extending Marionette

This proposed implementation allows Marionette Views to be extended and composed of individual addons and mixins (currently referred to as 'augments' or 'augmentations').

An example of functionality breaking down Marionette core is abstracting the login in `Layout` to a `RegionManager` augment that can be implemented like so:

```
Marionette.Layout = Marionette.ItemView.augment(
Marionette.augment.RegionManager
);
```

This, alone, allows the region functionality available normally only in Layout to be used in any other view, Marionette core or otherwise:

```
var CompositeLayout = Marionette.CompositeView.augment(
Marionette.augment.RegionManager
);
```

It also allows for chains of augmentations that can make combinations that may not have been previously planned on, an example shown in the repo [marionette.augment.inlineregions](https://github.com/jsoverson/marionette.augment.inlineregions)

```
var MyView = Marionette.ItemView.augment(
Marionette.augment.RegionManager,
Marionette.augment.InlineRegions
);
```

The code for `.augment()` inverts the relationship between the views, allowing the augment to alter the caller and return the extended calling view. In the examples given this is done to essentially just implement a reverse `.extend()` but the extending functionality is not set in stone. This was intentional to just provide an avenue for extension but allow for things we did not plan for.

```
// A class method in Marionette.View
augment : function(/* augments... */) {
var self = this;
for (var i = 0; i < arguments.length; i++) {
var aug = arguments[i];
if (aug.augment) {
self = aug.augment(self);
}
}
return self;
}
```

I'm open to alternate naming, "augment" is the first reasonable option I came across.