A0fkgvnqul556xxypfrf

Quick Wins with Backbone.js

Philip Woo

On one of our projects, we had an opportunity to refactor our existing code to use Backbone.js. We felt that Backbone was a good choice since we were dealing with improving some javascript components in our app and not looking to rewrite our entire app itself, which other JS frameworks (ala Angular.js, Ember.js) would have been better suited to do. Here are examples of some quick wins we managed to gain by taking advantage of the nice tools that Backbone.js gave us.

Backbone.js likes to REST

Our code had various CoffeeScript classes, most of which had similar looking functions like these:

 class Scenario save: -> $.ajax 'some/url' type: 'POST' dataType: 'json' data: { step: {foo: 'bar', ping: 'pong'} } success: (data, status, jqXHR) -> ... error: (jqXHR, textStatus, errorThrown) -> ... findAll: (scenarioId)-> $.ajax 'some/url' type: 'POST' dataType: 'json' data: { step: {foo: 'bar', ping:...