kadamwhite/backbone-wordpress-demo — pull request #12 by kadamwhite (2013-08-15 18:55:05+00:00)
Title: Break Backbone Model and View definitions into separate files

This is a small project, but in a larger application it is very helpful to work with many small files rather than one monolithic one. Finding what you want requires less scrolling, and there are many fewer opportunities for your code changes to collide with your teammate's if code is properly broken out.

The way we are doing this is to re-use the existing `artgallery` namespace object we created to store our templates, by defining two objects (`models` and `views`) as properties of `artgallery`. We then reference the constructors for our model and view off of the global namespace using those objects, e.g. `var myView = new artgallery.views.FeaturedArtwork({ model: myModel });`.

I recommend using a package manager such as [Require.js](http://requirejs.org/) to handle your script dependencies; even if you use WordPress to enqueue the final file, Require can be used as a helpful build step. The main reason we are not including it here is to limit the number of moving parts in this demo -- i.e., it is hopefully easier to see how Backbone works when you aren't also trying to understand a module loader at the same time.