Reputation: 3744
This is a single question, but I have all my head about the fact if this is a good practice or not.
Basically, let's say we have this trivial scenario:
(function(){
window.App = {
Models: {},
Collections: {},
Views: {}
};
App.Models.Person = Backbone.Model.extend({});
App.Views.PersonView = Backbone.View.extend({});
App.Collections.PeopleCollection = Backbone.Collection.extend({});
var person = new App.Person();
})();
So... if we are working on a small application, maybe it is ok, but when working on large size applications, it is ok to grab all the application into a self invoking anonimous function?, or what other practices do u guys point me out?
Upvotes: 2
Views: 346
Reputation: 960
If you're building out a Backbone app of any non-trivial size, go with RequireJS. I'd recommend their Sugar Notation. The benefits to this approach:
What this means is you save the namespacing for your directory structure. How you define the variables representing the classes is more of a "gentleman's agreement".
Upvotes: 2
Reputation: 7133
We decided to use RequireJS to organize our huge codebase. It turned out great.
It encourages modular and clean structure. We ended up without having a single window.Whatever
globally visible stateful troublemaker, and we like it.
If you're new to Backbone/RequireJS I recommend you the following tutorial:
http://backbonetutorials.com/organizing-backbone-using-modules/
Upvotes: 2