Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the basic purpose and benefits of backbone.js? [closed]

I have heard a lot of news that backbone.js will be very useful when working with html5 and node.js. I've read the documentation but I still can't get the basic purpose of backbone.js.

Can someone please explain it to me in simple terms. Also if you can direct me to good tutorials.

Thanks

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

like image 732
user1441945 Avatar asked Dec 16 '22 22:12

user1441945


2 Answers

Pretty much every rich-client web application out there has one or more lists of objects, and when you do something, one of those objects needs to change how it's displayed. Think of a TODO list, which is the canonical example for Backbone.js. Here are some ways you might do it:

  • When you make a change, use jQuery or something like that to change the text of the HTML div itself. But what about when you want to save it to the server? Do you read off the text of all the HTML divs, making that the authoritative place for the data? That just feels clunky! And what if you have other state that you don't want to display to the user? Or if you want to display the same object in two different places?

  • When you make a change, update a plain-old Javascript object somewhere, like window.todos = [{id:1, foo:'bar'},...]. But when you change it, you have to re-render everything that uses that object, and also tell the server about the changes. And if you have two or more different ways to change the state, such as a "mark all completed" feature for our TODOs app, then you'll end up repeating yourself quite a bit!

Backbone.js solves this problem by creating a Backbone.Model for each TODO object that holds the authoritative version of the data. Whenever you change an attribute on the model, no matter where you change it from, it notifies all the Views of that object to re-render. And you can sync an entire collection of models to a RESTful server with a single function call. Your app will be much more maintainable, and you'll be able to add arbitrary features much more easily.

like image 57
btown Avatar answered Jan 11 '23 22:01

btown


backbone.js is a MVC framework which helps you to organize your code properly and will be very helpful and easy when you are reusing it.

It is light weight.

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

like image 32
sundeep Avatar answered Jan 12 '23 00:01

sundeep