Vertebrae framework

built with Backbone.js and RequireJS using AMD

Backbone.js : List of Best Practices


Frontend Framework built with Backbone.js, Require.JS


  • No “var that = this;” usage
    • be descriptive if assigning this to a variable
    • try not to pass “this” as context as much as possible
  • Use Backbone, Underscore and RequireJS conventions as much as possible
    • the frontend favors convention over configuration
  • Use the CollectionView for managing a the relationship between a Collection and the View that relates to those models.
  • Need to define a more formal ViewManager class or define a set of best practices
  • The Backbone.Model.parse method should only be used for things like virtual fields
    • example: the member model may create a name field that concats first and last names
    • most parsing should be done on the sync specific to that version
  • Use small views and templates
    • rendering (and re*rendering) is faster and the DOM is easier to maintain
  • All dependencies must go through RequireJS require() or define() functions
    • no global state even for jQuery, Backbone, Underscore, etc
  • No manual jQuery DOM manipulation
    • the DOM fragments should be rendered through the View objects
  • No logic in the templates
    • too hard to test the logic
    • use Mustache templates only
  • Base classes are used for Models, Collections, and Views to add common behavior
  • Unit tests should be maintained using Jasmine (BDD style) for site*wide scripts:
    • e.g. models, views, collections, base classes and (utils) libraries
  • Comments should use // syntax, and also may include markdown syntax
    • docco documentation generator parsed best with //.
    • Routinely run docco (node package) to generate documentation (html files)
      • at least, following major releases.
  • Maintain examples by documenting best practices (Backbone and RequireJS) within code repository
    • docco generates a docs folder; each package should have a docs folder
    • docs folder has implementation notes highlighting frontend standards.
  • Document the build process using RequireJS Optimizer