marionettejs/backbone.marionette — pull request #1217 by jasonLaster (2014-04-22 02:53:23+00:00)
Title: Improve Behavior initialize so that it has access to view's options

Behaviors are instanciated before the Backbone's View constructor is called. Consequently, the view has not set its model when we're inside a behavior's initialize callback.

This change moves the Behaviors setup step below, the view's options set call. This way, the behavior now has access to the view's options through the `options` property.

```js
Behavior.extend({
initialize: function(options, view) {
view.model // undefined
view.options.model // set
}
});
```

---

### Alternatives
While, it's really important for the behavior to have access to the view's model when initializing, it's not essential how it gets it. I can think of two other ways this can be done:

1. pass view options the Behavior initialize function `initialize: function(behaviorOptions, view, viewOptions)`. This is okay, but it means adding a little more explicit behavior setup wiring. Also, it means that behaviors *have* to be setup in the View's instanciation loop, this is okay now, but could be limiting later if we want to make the api more flexible.

2. move behavior setup below `Backbone.View` constructor. This is theoretically nice, but it would mean that we'd have to re-call delegateEvents and bindUIElements to wireup the behaviors.