Search code examples
backbone.jsnamespaces

Backbone Namespace convention best practice


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?


Solution

  • 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/