Created
November 20, 2012 19:51
-
-
Save JeffreyWay/4120585 to your computer and use it in GitHub Desktop.
What do you prefer?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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; |
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
first one