What is the main purpose and benefits of backbone.js?

I heard a lot of news that backbone.js will be very useful when working with html5 and node.js I read the documentation, but I still cannot get the main purpose of backbone.js .

Can someone please explain this to me in simple words. Also, if you can direct me to good lessons.

thanks

Edit: see this question. What is the purpose of backbone.js?

+4
source share
2 answers

Almost every rich client web application has one or more lists of objects, and when you do something, one of these objects should change the way it is displayed. Think of the TODO list, which is a canonical example for Backbone.js. Here are some ways to do this:

  • When making changes, use jQuery or something similar to change the text of the HTML div itself. But what about when you want to save it to the server? Do you read the text of all sections of HTML, making it an authoritative place for data? This is just uncomfortable! And what if you have another state that you donโ€™t want to show to the user? Or if you want to display the same object in two different places?

  • When you make changes, update a simple Javascript object somewhere, for example window.todos = [{id:1, foo:'bar'},...] . But when you change it, you must redisplay everything that uses this object, and also inform the server about the changes. And if you have two or more different ways to change the state, for example, โ€œmark all completedโ€ function for our TODOs application, then in the end you will repeat a little!

Backbone.js solves this problem by creating a Backbone.Model for each TODO object that contains a valid version of the data. Whenever you change an attribute on a model, no matter where you change it, it notifies all representations of this object for reprocessing. And you can synchronize the entire set of models with a RESTful server with a single function call. Your application will be much more convenient to maintain, and you can easily add arbitrary functions.

+11
source

backbone.js is an MVC framework that helps you organize your code correctly and will be very useful and easy to reuse.

It is light weight.

you can find a good tutorial at http://thomasdavis.github.com/2011/02/01/backbone-introduction.html

+1
source

All Articles