SlideShare a Scribd company logo
Underscore & Backbone
Underscore
  Underscore is a utility belt for Javascript
Supports Functional Programming
Accessed as the '_' object

  _.is_NaN(...)

  _.extend(...)

  _.each(...)

Uses standard Javascript objects
Better Tests
● _.isNaN() - returns false with undefined

● _.isEqual() - full deep-compare, very

  efficient

● Standard form - _.isFunction, _.

  isString, _.isUndefined.
Extend for Mixins
_.extend(object, mixins)

● Works on any Javascript object

● Mixins are just standard JS objects too
{
  addon_function: function()....
  another_addon: function() ...
}
bind and bindAll
bind makes 'this' useful again

_.bind(function, context, [*args])

Returns a function that has a consistent 'this'
context.

_.bindAll(object) will bind all object's
properties with object as the context
Chain, Tap and Value
_.chain(value) returns a wrapped value,
which will stay wrapped until _.value() is
called

_([42, 43]).chain()
    .first()                                   // 42
    .take(function(val) { return val * 2 })   // 42 * 2
    .value()                                  // 84



_.tap() let's you temporarily unwrap the value
inside the chain
So Much More
● Safer keys, values, lastIndexOf,
  hasOwnProperty
● Array math (union, difference, sorting)
● Lightweight Templating
● All Under 4kb
Backbone Models
Backbone Models hold JSON data, typically
fetched from an external REST API

Backbone Models are defined with
Underscore's extend method

Backbone.Model.extend({
... model definition ...
});
Defaults
Backbone Models can define defaults which it
also borrows from Underscore

var Meal = Backbone.Model.extend({
  defaults: {
    "appetizer": "caesar salad",
    "entree":     "ravioli",
    "dessert":    "cheesecake"
  }
});
fetch/save
Calling fetch() on a Backbone Model is
analogous to a "GET" of that resource.

Calling save() is analogous to a "PUT"

model.fetch();
// make changes to model data
model.save();
Backbone.sync
All I/O on Backbone Models is done with
Backbone.sync

By default, Backbone.sync implements it's
CRUD methods on an AJAX backend.

There exist alternate implementations, such as
backbone.localStorage and backbone.
mongodb

Or you can write your own ...

More Related Content

PPTX
Introduction to JavaScrtipt
PDF
Core Data with multiple managed object contexts
PPTX
Core Data Performance Guide Line
PDF
Python my SQL - create table
PDF
Codegeneration With Xtend
PDF
High Performance Core Data
PDF
Python my sql database connection
PDF
Create a Core Data Observer in 10mins
Introduction to JavaScrtipt
Core Data with multiple managed object contexts
Core Data Performance Guide Line
Python my SQL - create table
Codegeneration With Xtend
High Performance Core Data
Python my sql database connection
Create a Core Data Observer in 10mins

What's hot (20)

PPT
Backbonejs
PDF
Building DSLs With Eclipse
PDF
Adventures in Multithreaded Core Data
PDF
Js objects
PDF
C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter
DOCX
Ruby on Rails Developer - Allerin
PPTX
React hooks
PDF
"this" in JavaScript
PPTX
Modular javascript
PDF
React Internals
PDF
20190627 j hipster-conf- diary of a java dev lost in the .net world
PDF
Multi-threaded CoreData Done Right
PPTX
Creating Single Page Web App using Backbone JS
PDF
Ten useful JavaScript tips & best practices
PPT
This pointer .17
PDF
Understanding react hooks
PPT
Digesting jQuery
PDF
Funcitonal Swift Conference: The Functional Way
PPTX
Backbonejs
Building DSLs With Eclipse
Adventures in Multithreaded Core Data
Js objects
C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter
Ruby on Rails Developer - Allerin
React hooks
"this" in JavaScript
Modular javascript
React Internals
20190627 j hipster-conf- diary of a java dev lost in the .net world
Multi-threaded CoreData Done Right
Creating Single Page Web App using Backbone JS
Ten useful JavaScript tips & best practices
This pointer .17
Understanding react hooks
Digesting jQuery
Funcitonal Swift Conference: The Functional Way
Ad

Viewers also liked (12)

PPT
East 55th & Euclid Avenue Crossroads Study Images
PPT
Bizim canımız çağıl hocamıza gelsin
PDF
Xerox mac
PDF
A Rubyist Tries AngularJS
PDF
mHealth regulations - Global efforts and readiness _White paper_DELL
PDF
PhoneGap - JavaScript for Mobile Apps
PDF
Digital technologies are driving a new generation of telehealth_White paper_DELL
PDF
PDF
An Intro to AngularJS
PPT
JavaScript State of the Union - Jan 2013
PPT
Gok turks
East 55th & Euclid Avenue Crossroads Study Images
Bizim canımız çağıl hocamıza gelsin
Xerox mac
A Rubyist Tries AngularJS
mHealth regulations - Global efforts and readiness _White paper_DELL
PhoneGap - JavaScript for Mobile Apps
Digital technologies are driving a new generation of telehealth_White paper_DELL
An Intro to AngularJS
JavaScript State of the Union - Jan 2013
Gok turks
Ad

Similar to Underscore and Backbone Models (20)

PPT
Backbone.js
PDF
Tikal's Backbone_js introduction workshop
KEY
Give Your JavaScript Apps Some Spine
PDF
Backbone.js: Run your Application Inside The Browser
KEY
Give Your JavaScript Apps A Spine
PDF
Backbone.js
PDF
Resumen Backbone.js en Ingles
PPTX
Backbone
PDF
Backbone
PDF
PPTX
Backbone the Good Parts
PDF
Javascript the New Parts v2
PDF
Developing maintainable Cordova applications
PDF
Deep Dive into Backbone.js Internals + Underscore.js
PPT
Backbone introdunction
PDF
Short intro to ECMAScript
KEY
【前端Mvc】之豆瓣说实践
PPTX
Binary Studio Academy PRO. JS course. Lecture 2. backbone
PDF
Backbone.js introduction workshop
PDF
Introduction to Backbone - Workshop
Backbone.js
Tikal's Backbone_js introduction workshop
Give Your JavaScript Apps Some Spine
Backbone.js: Run your Application Inside The Browser
Give Your JavaScript Apps A Spine
Backbone.js
Resumen Backbone.js en Ingles
Backbone
Backbone
Backbone the Good Parts
Javascript the New Parts v2
Developing maintainable Cordova applications
Deep Dive into Backbone.js Internals + Underscore.js
Backbone introdunction
Short intro to ECMAScript
【前端Mvc】之豆瓣说实践
Binary Studio Academy PRO. JS course. Lecture 2. backbone
Backbone.js introduction workshop
Introduction to Backbone - Workshop

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PPTX
Tartificialntelligence_presentation.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PPTX
Machine Learning_overview_presentation.pptx
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Assigned Numbers - 2025 - Bluetooth® Document
Mobile App Security Testing_ A Comprehensive Guide.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Tartificialntelligence_presentation.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
SOPHOS-XG Firewall Administrator PPT.pptx
Machine Learning_overview_presentation.pptx
NewMind AI Weekly Chronicles - August'25-Week II
A comparative analysis of optical character recognition models for extracting...
Heart disease approach using modified random forest and particle swarm optimi...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
A Presentation on Artificial Intelligence
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Group 1 Presentation -Planning and Decision Making .pptx
Spectral efficient network and resource selection model in 5G networks
Network Security Unit 5.pdf for BCA BBA.
Building Integrated photovoltaic BIPV_UPV.pdf

Underscore and Backbone Models

  • 2. Underscore Underscore is a utility belt for Javascript
  • 3. Supports Functional Programming Accessed as the '_' object _.is_NaN(...) _.extend(...) _.each(...) Uses standard Javascript objects
  • 4. Better Tests ● _.isNaN() - returns false with undefined ● _.isEqual() - full deep-compare, very efficient ● Standard form - _.isFunction, _. isString, _.isUndefined.
  • 5. Extend for Mixins _.extend(object, mixins) ● Works on any Javascript object ● Mixins are just standard JS objects too { addon_function: function().... another_addon: function() ... }
  • 6. bind and bindAll bind makes 'this' useful again _.bind(function, context, [*args]) Returns a function that has a consistent 'this' context. _.bindAll(object) will bind all object's properties with object as the context
  • 7. Chain, Tap and Value _.chain(value) returns a wrapped value, which will stay wrapped until _.value() is called _([42, 43]).chain() .first() // 42 .take(function(val) { return val * 2 }) // 42 * 2 .value() // 84 _.tap() let's you temporarily unwrap the value inside the chain
  • 8. So Much More ● Safer keys, values, lastIndexOf, hasOwnProperty ● Array math (union, difference, sorting) ● Lightweight Templating ● All Under 4kb
  • 9. Backbone Models Backbone Models hold JSON data, typically fetched from an external REST API Backbone Models are defined with Underscore's extend method Backbone.Model.extend({ ... model definition ... });
  • 10. Defaults Backbone Models can define defaults which it also borrows from Underscore var Meal = Backbone.Model.extend({ defaults: { "appetizer": "caesar salad", "entree": "ravioli", "dessert": "cheesecake" } });
  • 11. fetch/save Calling fetch() on a Backbone Model is analogous to a "GET" of that resource. Calling save() is analogous to a "PUT" model.fetch(); // make changes to model data model.save();
  • 12. Backbone.sync All I/O on Backbone Models is done with Backbone.sync By default, Backbone.sync implements it's CRUD methods on an AJAX backend. There exist alternate implementations, such as backbone.localStorage and backbone. mongodb Or you can write your own ...