I know it might sound like overkill in the beginning, but as we go along we’ll add more and more complexity, including Models, Subviews and Collections. These Views will have models and collections.ģ.2 Setting up Backbone.js App from Scratchįirstly, we’re going to build a typical starter “Hello World” application using Backbone.js and the model-view-controller (MVC) architecture. In our concise example, we’ll have one main Router that has Views. For example, an application can have a Model that has Views and each View that has collections. Backbone.js is very flexible and should be used according to the specific needs. The recommended usage is that Views usually have one Collection or one Model. For example, for path /books we’ll render books view. The router can create and call methods of other classes such as Views, Collections, and Models. From that class all the routes (URL paths) will be defined. Model: an individual data item with extra helpersĪ typical Backbone.js app will have the main Router class. Collection: a list of models with extra helpers such as fetch().View: methods related to browser&user events, HTML output (rendering).There are just four classes in Backbone.js: Backbone.js View and Subviews with Backbone.js Underscore.js.Event Binding with Backbone.js and jQuery.Dependencies for the Backbone.js Project.The example is the apple database application. This is not your typical to-do list, examples of which you can find plenty at TodoMVC, but a simplified application that is easier to understand but that still uses all components: views, collections, subviews, models, and event binding. Therefore, we’ll demonstrate how to build a Backbone.js simple application from scratch. Which one to choose depends on whether developers will have to customize a lot (go with lightweights) or use right-out-of-the-box (go with heavyweights).Ī bit of trivia: Backbone.js was created by the same person ( Jeremy Ashmenas) that brought CoffeeScript and Underscore.js to the world! If we draw a quick comparison between Backbone.js and other frameworks (not a fair one but still might be useful for some readers), it will be somewhere in the middle in complexity and features between Spine& KnockoutJS (the lighter side) and Ember.js& Angular.js (heavier side). If you are reading this chapter, you’re probably familiar with the benefits of using an MV* (asterisk means a controller, another view or something else) over plain jQuery that grows into unmanageable spaghetti code with time and added complexity.īackbone.js is the cornerstone of all JavaScript frameworks because it’s one of the most mature (i.e., dependable) and popular solutions in the ever-growing multitudes of browser JavaScript MV* (model-view-controllers and model-view-something) frameworks. Backbone.js FUNdamentals: The Cornerstone of JavaScript MV* Frameworks JavaScript and Node FUNdamentals: A Collection of Essential Basics (2014) 3.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |