The changelog to Backbone.js 1.1.0 states:
Backbone Views no longer automatically attach options passed to the constructor as this.options, but you can do it yourself if you prefer.
My question is how can I do it now? previously, I had this.var = this.options.var
regularly in my views.
Also worth taking a look a backbone.viewOptions for a minimalist implementation of view options that supports white listing and default values.
If you want to access to passed options - just save them:
If you use ES6:
If you want to save passed options for all
Backbone.View
's you can overrideconstructor
like ncksllvn suggested below.My team was already invested in using
this.options
in certain instances, and I didn't want to go through and modify theinitialize
method for every subclass of Backbone.View. As soon as Backbone is loaded, we override the Backbone.Viewconstructor
similiar to McGarnagle's answer, but with seamless integration: