alekop
alekop

Reputation: 3026

Marionette - constructor vs initialize

I noticed that Marionette views define a constructor method, instead of initialize. What's the purpose of it - why not just use Backbone's initialize, which is still being called during instantiation?

Upvotes: 1

Views: 476

Answers (1)

joews
joews

Reputation: 30330

It's common to implement initialize in your own View types.

If Marionette Views used initialize, you would need to remember to call the parent method to get the default behaviour. Most of your Views would look like this:

var MyView = Marionette.ItemView.extend({
  initialize: function(options) {
    Marionette.ItemView.prototype.initialize.call(this);
    this.x = options.x;
  }
});

This isn't necessary because Marionette uses constructor rather than initialize.

Upvotes: 1

Related Questions