Skip to content

Comment on An Intro to Backbone.js: Part 2 - Controllers and Viewsparent

Comments

What advantage do backbone.js models provide over javascript objects?

Event binding, refreshing to the server, dirty tracking, etc.

Basically, the pattern is: get JSON doc from the server, inflate it into a model, hook in a view, and then as you mutate the model, in code or the UI, the UI and server are updated. Can you write this yourself? Of course. Do you want to? That's up to you.

Personally, I find Backbone's sugar most useful for views. You make a DOM element that represents your thing, and then you program in terms of that thing, and the UI "just works". It's wonderful.

Anyway, Backbone is absolutely not overkill. It's just what many apps need, and you can use as much of it as you want.

(I should point out that I don't do server-side HTML anymore. My web apps are JSON/REST endpoints that also serve a few pieces of static HTML, JS, and CSS. Everything UI-related is done on the client side. Backbone makes this amazingly easy.)

This is also a particularly good pattern for mobile applications as well. Your app serves a tiny page, and then lets it load the data basically in the background. Combine with some localstorage to show the information from the last time they were there right away, and you can make apps that feel significantly more responsive than they were before.

"My web apps are JSON/REST endpoints that also serve a few pieces of static HTML, JS, and CSS."

^^^^ THIS

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.