Skip to content

Commit

Permalink
Merge pull request #767 from marionettejs/sjs/move-options-assignment
Browse files Browse the repository at this point in the history
[fix] Move the instatiation of view options above the constructor
  • Loading branch information
samccone committed Oct 31, 2013
2 parents 4dd1a9f + 044ed52 commit 6485c5b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 13 additions & 0 deletions spec/javascripts/view.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,19 @@ describe("base view", function(){
});
});

describe("should expose its options in the constructor", function() {
var View = Marionette.View.extend({
initialize: function() {
this.info = this.options;
}
});

it("should be able to access instance options", function() {
var myView = new View({name: "LeChuck"});
expect(myView.info.name).toBe("LeChuck");
});
});

describe("when closing a view that is already closed", function(){
var close, view;

Expand Down
7 changes: 6 additions & 1 deletion src/marionette.view.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ Marionette.View = Backbone.View.extend({
_.bindAll(this, "render");

var args = Array.prototype.slice.apply(arguments);
Backbone.View.prototype.constructor.apply(this, args);

// this exposes view options to the view initializer
// this is a backfill since backbone removed the assignment
// of this.options
// at some point however this may be removed
this.options = options || {};
Backbone.View.prototype.constructor.apply(this, args);

Marionette.MonitorDOMRefresh(this);
this.listenTo(this, "show", this.onShowCalled, this);
Expand Down

0 comments on commit 6485c5b

Please sign in to comment.