Search code examples
backbone.jsbackbone-views

Making Backbone.View options mandatory


I am new to Backbone, and I have found myself writing views which rely on values of the options object to function properly. In other words, my options are mandatory. That doesn't sound right, so I'm wondering if perhaps I'm misusing the options parameter, and if so, what's a better way of doing things?


Solution

  • Dependency injection is a not bad practice at all. It's actually common practice especially dealing with Views. It also makes it easier to unit test your view. So using the options to get some required attributes to build your View is completely OK. Maybe a you could share some examples of what you think is wrong?