- Backbone.js Testing
- Ryan Roemer
- 595字
- 2021-08-13 16:48:30
A Backbone.js refresher
Although this book assumes a comfortable level of familiarity with Backbone.js, Underscore.js, and jQuery, we will briefly touch upon the basics of Backbone.js application development.
Backbone.js provides abstractions and useful functionality for architecting and developing JavaScript web applications. Backbone.js brings order to the chaotic interactions between program and display logic, DOM events, and backend communication. This is achieved via what could loosely be considered a Model-View-Controller (MVC) paradigm that separates application code into the following topics:
- Data modeling and retrieval
- Display rendering and user interactivity
- Brokering data and display logic to appropriately bind and manipulate data models and user interfaces
Note
Backbone.js does not completely follow a traditional MVC approach, causing some observers to call it an MV* framework. An MV* application has a model and a view but has something other than a controller connecting the model and the view. For a much more detailed discussion on MVC and the various MV* approaches, see Developing Backbone.js Applications by Addy Osmani, and the article, Journey Through The JavaScript MVC Jungle (http://coding.smashingmagazine.com/2012/07/27/journey-through-the-javascript-mvc-jungle/).
To this end, Backbone.js provides a set of core library components:
- Events: The
Backbone.Events
module gives JavaScript objects the ability to emit and respond to events, including built-in Backbone.js class events as well as custom application events. - Models: The
Backbone.Model
class provides a data wrapper that can synchronize with a backend, validate data changes, and emit events to other parts of a Backbone.js application. A model is the fundamental unit of data in a Backbone.js application. - Collections: The
Backbone.Collection
class wraps a set of models in an ordered list. Collections provide events, backend synchronization, and many helper methods for manipulating and mutating the set of underlying models. - Templates: Backbone.js leaves the choice of the template library up to the developer (we will use Underscore.js templates for this book). Other popular template alternatives include Handlebars (http://handlebarsjs.com/), Mustache (https://github.com/janl/mustache.js/), and EJS (http://embeddedjs.com/).
- Views: A
Backbone.View
object is the glue that binds models, collections, and templates together with the browser environment and DOM. Backbone.js is deliberately agnostic as to what a view must do, but a typical view references a collection or a model, couples data to the user interface via a template, and mediates user interaction and backend server events. To clarify potentially confusing terminologies,Backbone.View
is much more analogous to a traditional MVC controller, and a Backbone.js template acts like an MVC view. - Routers: Backbone.js programs are commonly developed as single-page applications in which the entire HTML page source and JavaScript libraries are downloaded in a single page load.
Backbone.Router
maintains the internal state of the application and manages the browser history. Routers provide client-side routing via URL hash fragments (#app-page
) to allow different views to be linked to, bookmarked, and navigated like traditional web pages.
In the chapters that follow, we will test these components separately and together, so it is important to ensure a solid grasp of the fundamentals. The core documentation at http://backbonejs.org is a good starting point for the concepts, API, and pointers and tips on application development. For a deeper dive into Backbone.js topics, there are many great online and print resources, including:
- Developing Backbone.js Applications by Addy Osmani, which is a Creative-Commons-licensed book developed with the help of the open source community on GitHub. This book discusses the theory, architecture, and fundamentals of creating Backbone.js applications (https://github.com/addyosmani/backbone-fundamentals).
- Derick Bailey's Blog, which is a blog that is frequently updated with many Backbone.js posts and has been written by the creator of
Backbone.Marionette
(http://lostechies.com/derickbailey/category/backbone/). - The official Backbone.js wiki page that aggregates blog posts, tutorials, and working examples (https://github.com/documentcloud/backbone/wiki/Tutorials%2C-blog-posts-and-example-sites).
- 手機安全和可信應用開發指南:TrustZone與OP-TEE技術詳解
- arc42 by Example
- Hands-On Data Structures and Algorithms with JavaScript
- Twilio Best Practices
- 新編Premiere Pro CC從入門到精通
- 深入RabbitMQ
- Building RESTful Python Web Services
- C語言程序設計
- Android項目實戰:手機安全衛士開發案例解析
- 自學Python:編程基礎、科學計算及數據分析(第2版)
- 遠方:兩位持續創業者的點滴思考
- NGUI for Unity
- Learning D
- Sitecore Cookbook for Developers
- 編程的原則:改善代碼質量的101個方法