Skip to content

Instantly share code, notes, and snippets.

@JeffreyWay
Created November 20, 2012 19:51
Show Gist options
  • Select an option

  • Save JeffreyWay/4120585 to your computer and use it in GitHub Desktop.

Select an option

Save JeffreyWay/4120585 to your computer and use it in GitHub Desktop.
What do you prefer?
// In Backbone, when passing a collection around, do you prefer to inject the
// collection into the view, or store it on a global namespace?
// Injection
var SomeCollectionView = Backbone.View.extend({
initialize: function() {
// this.collection
}
});
new SomeCollectionView({ collection: App.myCollection });
// Or store and reference collection on namespace.
var SomeCollectionView = Backbone.View.extend({
initialize: function() {
// App.myCollection
}
});
new SomeCollectionView;
@sergiomedinag
Copy link

Dependency injection is the best way to handle that. As pointed before, it makes unit testing easier and makes the app more portable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment