KEMBAR78
Organized web app development using backbone.js
(ORGANIZED) WEB-APP DEVELOPMENT USING
BACKBONE.JS
SHAKTI SHRESTHA
shakti.shrestha@gmail.com
ABOUT ME
I work at Miracle Interface as Chief Technical
Officer.
Software Architect
Focus on delivering applications with good
performance
ABOUT ME
A certified OCP in oracle 10g.
a Programmer by heart.
Also involved with ASPNETCOMMUNITY
AGENDAS
Problems facing with jQuery-only
Application
Solution
Backbone
Backbone :: Architecture
Tips
Problems facing with jQuery-only Application
Problems facing with jQuery-only application
Data is tightly coupled with DOM
jQuery Callback is hell
Mostly get lost in forest of jQuery selectors and
callbacks
Scripts get scattered
Problem while debugging code
Problems facing with jQuery-only application
Data is tightly coupled with DOM
Problems facing with jQuery-only application…
Data is tightly coupled with DOM
Problems facing with jQuery-only application…
jQuery Callback is hell
Problems facing with jQuery-only application…
Mostly get lost in forest of
jQuery selectors and callbacks
Problems facing with jQuery-only application…
Scripts get scattered
We love bugs
While trying to debug a jQuery application, I drink
lots of caffeine
Solution?
SOLUTION
Decoupling Data from UI
SOLUTION…
Abstraction
abstraction is the process of separating ideas from specific
instances of those ideas at work. Wikipedia
We already know about it.
Model/Collection
Views/Templates
Controller/Router
SOLUTION…
Callback Management (Events)
 Data & UI can be updated.
 Action & application status
SOLUTION…
Code Management
SOLUTION…
JS frameworks/libraries
AngularJs
BackboneJs
CanJs
EmberJs
MeteorJs
ExtJs
Backbone.js
BACKBONE.JS,
Its MV* structure
Backbone does not force you to use a single
template engine. Views can bind to HTML
constructed in your favorite way.
BACKBONE.JS
Can easily be used in existing application or in a
component of existing application.
The focus is on supplying you with helpful
methods to manipulate and query your data.
BACKBONE.JS
Synchronous events are used as the fundamental
building block.
 And if you want a specific event to be asynchronous and aggregated, no
problem.
http://underscorejs.org/#debounce
Backbone scales well, from embedded
widgets to massive apps.
BACKBONE.JS
Backbone is a library, not a framework, and plays well with
others.
Dojo
D3 visualization
Knockoutjs
Meteorjs
"Two way data-binding" is avoided.
Extension available.
BACKBONE.JS DEPENDS ON
Underscore.js
jQuery or Zepto
Json2.js
BACKBONE.JS IS BACKBONE OF
 Well known apps
 https://trello.com/
 https://delicious.com/
 http://www.khanacademy.org/
 & many more
 Project Done by my team
 Eternal Message
 Cocolink-discussion
 Startup project
 onTreat.com (WIP)
Backbone.js, components?
BACKBONE.JS :: COMPONENTS
Backbone.Model
Backbone.Collection
Backbone.View
Template (Underscore.js)
Router
MODEL
Presents data
Throws events
Reusable
Handles persistence
MODEL :: COMMUNICATE
RESTful
Fetch  http GET /url
Save(New)  http POST /url
Save  http PUT /url/id
Destroy  http DELETE /url/id
MODEL :: COMMUNICATE
For legacy web server without REST/HTTP.
Then use Backbone.emulateHTTP = true
MODEL :: DEFINE
key field
URL to perform
RESTful operation
MODEL :: USE
Create object of Model
class
Set data in
model
call the function to save it.
Model :: more…
http://backbonejs.org/#Model
Collection
List of models
Only used for pulling data from server.
Collection :: Define
Collection :: Use
Collection :: More…
http://backbonejs.org/#Collection
View
Dom manipulation
Dom event handling
Uses model/collection
View :: Define
html element where the
view will be rendered
View :: Define (with events)
Define events &
trigger point
function that will be
called when event is
triggered.
View :: Use
View :: more …
http://backbonejs.org/#View
Template
Default template engine is underscore.js
Can use other template engines,
Mustache
Handlebar
jQuery-tmpl
Template :: Define
Model’s
attribute
(data field)
Template :: Define
compile
templat
e
generat
e html
Routers
Maps hash url to function
Need to enable backbone history
Backbone.history.start();
Routers :: Define
Without
parameter
Routers :: Define
With
parameter
Routers :: Use
Tips
TIPS
 AMD
 Require.js, common.js
 MVC structure
 http://marionettejs.com/
 http://chaplinjs.org/
 Model-view binding
 Stickit
 Extensions, Plugins, resources
 https://github.com/jashkenas/backbone/wiki/Extensions%2C-Plugins%2C-Resources
 Tuts
 https://github.com/jashkenas/backbone/wiki/Tutorials%2C-blog-posts-and-example-sites
REFERENCES
http://backbonejs.org/
http://www.slideshare.net/nabeelahali/backbone-intro
http://www.slideshare.net/iloveigloo/clientside-mvc-with-
backbonejs
Questions
Thank you. 
THANK YOU 

Organized web app development using backbone.js