mozilla/talkilla — pull request #353 by n1k0 (2013-12-10 21:16:34+00:00)
Title: [WiP Proposal] BaseView to check and "inject" required dependencies

Following #351, this patch goes even further and introduces a new `BaseView#dependencies` object property to declare view dependencies; The idea is to turn code like:

```js
var MyView = Backbone.View.extend({
initialize: function(options) {
options = options || {};
if (!options.foo)
throw new Error("missing foo");
if (!options.bar)
throw new Error("missing bar");
this.foo = options.foo;
this.bar = options.bar;
}
});

var view = new MyView({q: "universe", a: 42});
console.log(view.q, view.a) // "universe" 42
```

into:

```js
var MyView = Backbone.View.extend({
dependencies: {
foo: String,
bar: Number
}
});

var view = new MyView({q: "universe", a: 42});
console.log(view.q, view.a) // "universe" 42
```

Notice the patch adds type validation as well as property checks.

Landing this is to be discussed, and the impl. to be challenged. We could also imagine expanding the use of this concept to other objects like models or apps, as it's not Backbone related.