marionettejs/backbone.marionette — pull request #1583 by jmeas (2014-07-08 00:15:42+00:00)
Title: Adds pickOptions helper.

Marionette heavily depends upon `this.options = options;` during instantiation of all of its Classes. This PR introduces a new pattern that can help us move away from this pattern. There are two reasons why I think we should begin moving away from it:

1. Backbone did away with the pattern some time ago ([ref](https://github.com/jashkenas/backbone/issues/2822) [ref](https://github.com/jashkenas/backbone/pull/2933) [ref](https://github.com/jashkenas/backbone/pull/2461)). Because of this, I think that we should, too.

2. It's code smell. Users can pass any options to any object and they're always merged. There's no contract made anywhere, so it's hard to understand which options are available in each Class.

Instead of this outdated pattern, this PR introduces two new features I've been using in my apps for quite some time with great success to fix this problem.

The first is `mergeOptions`. This is an array of keys that will be picked out from the options you pass in during instantiation and attached to the object directly. This pattern [was lifted straight from Backbone](https://github.com/jashkenas/backbone/blob/master/backbone.js#L1046), so those familiar with the Backbone source will find themselves writing very similar code that Backbone itself uses.

The second feature is `Marionette.pickOptions`, which extracts [the logic that picks out the mergeOptions](https://github.com/jashkenas/backbone/blob/master/backbone.js#L1037).

This allows us to write really great code that's more organized, easier to maintain, self-documenting, and more consistent with Backbone.

One day this will allow us to move away from the [`getOption` function](https://github.com/marionettejs/backbone.marionette/blob/master/src/marionette.helpers.js#L24-L37), which is one of the more gross methods in Marionette. In this respect, this preps us to solve #769 in the next major release by deprecating the act of accessing options through `this.options`.

FAQ:

- More tests? Sure. Just let me know what you'd like to see.
- Why was application left out? The application [already merges every option onto `this`](https://github.com/marionettejs/backbone.marionette/blob/master/src/marionette.application.js#L16), so there wouldn't be much point to it.
- No default mergeOptions? This should wait for v3 because it's likely breaking. It's the difference between something being `this.options.something` vs `this.something`