SlideShare a Scribd company logo
Радослав Станков
OpenFest           05/11/2011
Кой съм аз?

@rstankov




http://rstankov.com
http://github.com/rstankov
Browser




        Controller




Model                View


        Сървър
Browser




        Controller




Model                View


        Сървър
Browser




        Controller




Model                View


        Сървър
Browser




        Controller




Model                View


        Сървър
Browser




        Controller




Model                View


        Сървър
Browser




        Controller




Model                View


        Сървър
Browser




        Controller




Model                View


        Сървър
Browser




        Controller




Model                View


        Сървър
Browser




        Controller




Model                View


        Сървър
Browser




        Controller




Model                View


        Сървър
Browser




        Controller




Model                View


        Сървър
Browser




        Controller




Model                View


        Сървър
Browser




        Controller




Model                View


        Сървър
Browser
Dom




View




Model
Browser
Dom




View




Model
Browser
Dom




View




Model
Browser
Dom




View




Model
Browser
Dom




View




Model
Browser
Dom




View




Model
Browser
Dom




View




Model
Browser
Dom




View




Model
Browser
Dom




View




Model
Backbone.Events
var object = {};

$.extend(object, Backbone.Events);

object.bind('eventName', function() {
  console.log('1');
});

object.bind('eventName', function() {
  console.log('2');
});

object.trigger('eventName');

// prints '1' and '2'
var object = {};

$.extend(object, Backbone.Events);

object.bind('eventName', function() {
  console.log('1');
});

object.bind('eventName', function() {
  console.log('2');
});

object.trigger('eventName');

// prints '1' and '2'
var object = {};

$.extend(object, Backbone.Events);

object.bind('eventName', function() {
  console.log('1');
});

object.bind('eventName', function() {
  console.log('2');
});

object.trigger('eventName');

// prints '1' and '2'
var object = {};

$.extend(object, Backbone.Events);

object.bind('eventName', function() {
  console.log('1');
});

object.bind('eventName', function() {
  console.log('2');
});

object.trigger('eventName');

// prints '1' and '2'
var object = {};

$.extend(object, Backbone.Events);

object.bind('eventName', function() {
  console.log('1');
});

object.bind('eventName', function() {
  console.log('2');
});

object.trigger('eventName');

// prints '1' and '2'
Backbone.Model
var Person = Backbone.Model.extend({
  initialize: function(){
    console.log("I'm alive!");
  }
});

new Person();
var Person = Backbone.Model.extend({
  initialize: function(){
    console.log("I'm alive!");
  }
});

new Person();
var Person = Backbone.Model.extend({
  initialize: function(){
    console.log("I'm alive!");
  }
});

new Person();
var Person = Backbone.Model.extend({});

var me = new Person({name: 'Radoslav'});

me.get('name');                  // Radoslav
me.set({lastName: 'Stankov'});
me.get('lastName');               // Stankov
var Person = Backbone.Model.extend({});

var me = new Person({name: 'Radoslav'});

me.get('name');                  // Radoslav
me.set({lastName: 'Stankov'});
me.get('lastName');               // Stankov
var Person = Backbone.Model.extend({});

var me = new Person({name: 'Radoslav'});

me.get('name');                  // Radoslav
me.set({lastName: 'Stankov'});
me.get('lastName');               // Stankov
var Person = Backbone.Model.extend({});

var me = new Person({name: 'Radoslav'});

me.get('name');                  // Radoslav
me.set({lastName: 'Stankov'});
me.get('lastName');               // Stankov
var Person = Backbone.Model.extend({});

var me = new Person({name: 'Radoslav'});

me.get('name');                  // Radoslav
me.set({lastName: 'Stankov'});
me.get('lastName');               // Stankov
var Person = Backbone.Model.extend({
  defaults: {
    name: 'John',
    lastName: 'Doe',
  }
});

var me = new Person();
me.get('name'); // John
me.get('lastName'); // Doe
var Person = Backbone.Model.extend({
  defaults: {
    name: 'John',
    lastName: 'Doe',
  }
});

var me = new Person();
me.get('name'); // John
me.get('lastName'); // Doe
var Person = Backbone.Model.extend({
  defaults: {
    name: 'John',
    lastName: 'Doe',
  }
});

var me = new Person();
me.get('name'); // John
me.get('lastName'); // Doe
var Person = Backbone.Model.extend({
  defaults: {
    name: 'John',
    lastName: 'Doe',
  }
});

var me = new Person();
me.get('name'); // John
me.get('lastName'); // Doe
var Calculator = Backbone.Model.extend({
  defaults: {
    value: 0
  },
  value: function(){
    return this.get('value');
  },
  sum: function(value){
    this.set({value: value + this.get('value')});
  },
  reset: function(){
    this.set({value: 0});
  }
});
var Calculator = Backbone.Model.extend({
  defaults: {
    value: 0
  },
  value: function(){
    return this.get('value');
  },
  sum: function(value){
    this.set({value: value + this.get('value')});
  },
  reset: function(){
    this.set({value: 0});
  }
});
var Calculator = Backbone.Model.extend({
  defaults: {
    value: 0
  },
  value: function(){
    return this.get('value');
  },
  sum: function(value){
    this.set({value: value + this.get('value')});
  },
  reset: function(){
    this.set({value: 0});
  }
});
var Calculator = Backbone.Model.extend({
  defaults: {
    value: 0
  },
  value: function(){
    return this.get('value');
  },
  sum: function(value){
    this.set({value: value + this.get('value')});
  },
  reset: function(){
    this.set({value: 0});
  }
});
var Calculator = Backbone.Model.extend({
  defaults: {
    value: 0
  },
  value: function(){
    return this.get('value');
  },
  sum: function(value){
    this.set({value: value + this.get('value')});
  },
  reset: function(){
    this.set({value: 0});
  }
});
var cal = new Calculator();

cal.bind('change:value', function(model, value){
  console.log(value);
});

cal.bind('change', function(model){
  console.log(model.get('value'));
});

cal.bind('all', function(eventName) {
  console.log('I see every thing!', eventName);
});
var cal = new Calculator();

cal.bind('change:value', function(model, value){
  console.log(value);
});

cal.bind('change', function(model){
  console.log(model.get('value'));
});

cal.bind('all', function(eventName) {
  console.log('I see every thing!', eventName);
});
var cal = new Calculator();

cal.bind('change:value', function(model, value){
  console.log(value);
});

cal.bind('change', function(model){
  console.log(model.get('value'));
});

cal.bind('all', function(eventName) {
  console.log('I see every thing!', eventName);
});
var cal = new Calculator();

cal.bind('change:value', function(model, value){
  console.log(value);
});

cal.bind('change', function(model){
  console.log(model.get('value'));
});

cal.bind('all', function(eventName) {
  console.log('I see every thing!', eventName);
});
var cal = new Calculator();

cal.bind('myEvent', function(){
  console.log('KaBoom....');
});

cal.trigger('myEvent');
var Product = Backbone.Model.extend({
  urlRoot: '/products'
});

var chair = new Product({
  name: 'chair',
  price: 10
});

chair.save();

// POST /products
var Product = Backbone.Model.extend({
  url: function(){
    return '/products/' + (this.isNew() ? '' : this.id);
  }
});

var chair = new Product({
  id: 5,
  name: 'chair',
  price: 10
});

chair.save();

// PUT /products/1
http://documentcloud.github.com/backbone/#Model-save
И още...
• validate
• escape
• has
• unset
• clear
• hasChanged
• changedAttributes
• previousAttributes
• fetch
• toJSON
• clone
Backbone.View
var UserNameView = Backbone.View.extend({
   tagName: 'input',
   className: 'string optional',
   id:      'user-name',
   attributes: {
     type: 'string',
     name: 'user[name]'
   }
 });

 var userName = new UserNameView();

 console.log(userName.el);

<input type="string" name="user[name]" id="user-name" class="string optional">
var UserNameView = Backbone.View.extend({
   tagName: 'input',
   className: 'string optional',
   id:      'user-name',
   attributes: {
     type: 'string',
     name: 'user[name]'
   }
 });

 var userName = new UserNameView();

 console.log(userName.el);

<input type="string" name="user[name]" id="user-name" class="string optional">
var UserNameView = Backbone.View.extend({
   tagName: 'input',
   className: 'string optional',
   id:      'user-name',
   attributes: {
     type: 'string',
     name: 'user[name]'
   }
 });

 var userName = new UserNameView();

 console.log(userName.el);

<input type="string" name="user[name]" id="user-name" class="string optional">
var UserNameView = Backbone.View.extend({
   tagName: 'input',
   className: 'string optional',
   id:      'user-name',
   attributes: {
     type: 'string',
     name: 'user[name]'
   }
 });

 var userName = new UserNameView();

 console.log(userName.el);

<input type="string" name="user[name]" id="user-name" class="string optional">
var UserNameView = Backbone.View.extend({
   tagName: 'input',
   className: 'string optional',
   id:      'user-name',
   attributes: {
     type: 'string',
     name: 'user[name]'
   }
 });

 var userName = new UserNameView();

 console.log(userName.el);

<input type="string" name="user[name]" id="user-name" class="string optional">
var UserNameView = Backbone.View.extend({
   tagName: 'input',
   className: 'string optional',
   id:      'user-name',
   attributes: {
     type: 'string',
     name: 'user[name]'
   }
 });

 var userName = new UserNameView();

 console.log(userName.el);

<input type="string" name="user[name]" id="user-name" class="string optional">
var UserNameView = Backbone.View.extend({
   tagName: 'input',
   className: 'string optional',
   id:      'user-name',
   attributes: {
     type: 'string',
     name: 'user[name]'
   }
 });

 var userName = new UserNameView();

 console.log(userName.el);

<input type="string" name="user[name]" id="user-name" class="string optional">
var UsersListView = Backbone.View.extend({
  el: '#users-list'
});

var userList = new UsersListView();

console.log(userList.el);
var EditBoxView = Backbone.View.extend({});

var element = $('#edit-box-view').get(0),
  editBox = new EditBoxView({el: element});

console.log(editBox.el === element);
var DocumentView = Backbone.View.extend({
  events: {
    'dblclick':        'open',
    'click .grid .doc': 'select',
    'customEvent .title': 'custom'
  },
  open: function() {},
  select: function() {},
  custom: function() {}
});
var DocumentView = Backbone.View.extend({
  events: {
    'dblclick':        'open',
    'click .grid .doc': 'select',
    'customEvent .title': 'custom'
  },
  open: function() {},
  select: function() {},
  custom: function() {}
});
var DocumentView = Backbone.View.extend({
  events: {
    'dblclick':        'open',
    'click .grid .doc': 'select',
    'customEvent .title': 'custom'
  },
  open: function() {},
  select: function() {},
  custom: function() {}
});
var DocumentView = Backbone.View.extend({
  events: {
    'dblclick':        'open',
    'click .grid .doc': 'select',
    'customEvent .title': 'custom'
  },
  open: function() {},
  select: function() {},
  custom: function() {}
});
var DocumentView = Backbone.View.extend({
  events: {
    'dblclick':        'open',
    'click .grid .doc': 'select',
    'customEvent .title': 'custom'
  },
  open: function() {},
  select: function() {},
  custom: function() {}
});
var DocumentView = Backbone.View.extend({
  events: {
    'dblclick':        'open',
    'click .grid .doc': 'select',
    'customEvent .title': 'custom'
  },
  open: function() {},
  select: function() {},
  custom: function() {}
});
var DocumentView = Backbone.View.extend({
  events: {
    'dblclick':        'open',
    'click .grid .doc': 'select',
    'customEvent .title': 'custom'
  },
  open: function() {},
  select: function() {},
  custom: function() {}
});
<script type="text/template" id="news">
 <h1><%= title %></h1>
 <time><%= created_at %></time>
 <p><%= text %></p>
</script>
var NewsView = Backbone.View.extend({
  template: _.template($('#news').html()),
  render: function() {
    this.el.innerHTML = this.template(this.model);
    return this;
  }
});
var view = new NewsView({
  model: {
    title: "News Title",
    created_at: "Today",
    text: "Long text"
  }
});

document.body.appendChild(view.render().el);
<script type="text/template" id="news">
 <h1><%= title %></h1>
 <time><%= created_at %></time>
 <p><%= text %></p>
</script>
<div>
 <h1>News Title</h1>
 <time>Today</time>
 <p>Long text</p>
</div>
View




Model          DOM
View




Model          DOM
View




Model          DOM
View




Model          DOM
View




Model          DOM
View




Model          DOM
View




Model          DOM
View




Model          DOM
View




Model          DOM
View




Model          DOM
View




Model            DOM




        View 2
View




Model            DOM




        View 2
View




Model            DOM




        View 2
View




Model            DOM




        View 2
View




Model            DOM




        View 2
View




Model            DOM




        View 2
View




Model            DOM




        View 2
View




Model            DOM




        View 2
View




Model            DOM




        View 2
View




Model            DOM




        View 2
View




        View 2



Model            DOM
View




        View 2



Model            DOM
        View 3
View




        View 2



Model            DOM
        View 3




        View 4
View




         View 2



Model               DOM
         View 3




         View 4




        View .. N
View




         View 2



Model               DOM
         View 3




         View 4




        View .. N
View




         View 2



Model               DOM
         View 3




         View 4




        View .. N
View




         View 2



Model               DOM
         View 3




         View 4




        View .. N
View




         View 2



Model               DOM
         View 3




         View 4




        View .. N
View




         View 2



Model               DOM
         View 3




         View 4




        View .. N
View




         View 2



Model               DOM
         View 3




         View 4




        View .. N
View




         View 2



Model               DOM
         View 3




         View 4




        View .. N
View




         View 2



Model               DOM
         View 3




         View 4




        View .. N
Demo
var Calculator = Backbone.Model.extend({
  defaults: {
    value: 0
  },
  increment: function() {
    this.set({'value': this.get('value') + 1});
  },
  decrement: function() {
    this.set({'value': this.get('value') - 1});
  },
  getValue: function() {
    return this.get('value');
  }
});
var ButtonsView = Backbone.View.extend({
  events: {
    'click .plus': 'plus',
    'click .minus': 'minus'
  },
  plus: function() {
    this.model.increment();
  },
  minus: function() {
    this.model.decrement();
  }
});
var DisplayView = Backbone.View.extend({
  initialize: function() {
    this.model.bind('change:value', this.render, this);
    this.render();
  },
  render: function() {
    this.el.innerHTML = this.model.getValue();
    return this;
  }
});
var cal = new Calculator();

new ButtonsView({model: cal, el: '.buttons'});
new DisplayView({model: cal, el: '.display'});
Backbone.Collection
var ProductsCollection = Backbone.Collection.extend({
  model: Product
});

var products = new ProductsCollection();

products.fetch();

products.bind('reset', function(list) {
  console.log('Loaded', list.length, 'records');
});
products.bind('add', function(model) {
  console.log('new product added');
});

products.bind('remove', function(model) {
  console.log('item product removed');
});
И още...


• Underscore Methods
• add / remove / at
• sort / comparator
• reset
• create
• url
• toJSON
Backbone.Router
var AppRouter = Backbone.Router.extend({
  routes: {
    'pages':         'index',
    'pages/search/:q': 'search',
    'pages/:id':       'show'
  },
  initialize: function() {
    console.log('initialize');
  },
  index: function()        { /* code */ },
  search: function(query) { /* code */ },
  show: function(id) { /* code */ }
});

var app = new AppRouter();

Backbone.history.start();
var AppRouter = Backbone.Router.extend({
  routes: {
    'pages':         'index',
    'pages/search/:q': 'search',
    'pages/:id':       'show'
  },
  initialize: function() {
    console.log('initialize');
  },
  index: function()        { /* code */ },
  search: function(query) { /* code */ },
  show: function(id) { /* code */ }
});

var app = new AppRouter();

Backbone.history.start();
var AppRouter = Backbone.Router.extend({
  routes: {
    'pages':         'index',
    'pages/search/:q': 'search',
    'pages/:id':       'show'
  },
  initialize: function() {
    console.log('initialize');
  },
  index: function()        { /* code */ },
  search: function(query) { /* code */ },
  show: function(id) { /* code */ }
});

var app = new AppRouter();

Backbone.history.start();
var AppRouter = Backbone.Router.extend({
  routes: {
    'pages':         'index',
    'pages/search/:q': 'search',
    'pages/:id':       'show'
  },
  initialize: function() {
    console.log('initialize');
  },
  index: function()        { /* code */ },
  search: function(query) { /* code */ },
  show: function(id) { /* code */ }
});

var app = new AppRouter();

Backbone.history.start();
var AppRouter = Backbone.Router.extend({
  routes: {
    'pages':         'index',
    'pages/search/:q': 'search',
    'pages/:id':       'show'
  },
  initialize: function() {
    console.log('initialize');
  },
  index: function()        { /* code */ },
  search: function(query) { /* code */ },
  show: function(id) { /* code */ }
});

var app = new AppRouter();

Backbone.history.start();
var AppRouter = Backbone.Router.extend({
  routes: {
    'pages':         'index',
    'pages/search/:q': 'search',
    'pages/:id':       'show'
  },
  initialize: function() {
    console.log('initialize');
  },
  index: function()        { /* code */ },
  search: function(query) { /* code */ },
  show: function(id) { /* code */ }
});

var app = new AppRouter();

Backbone.history.start();
var AppRouter = Backbone.Router.extend({
  routes: {
    'pages':         'index',
    'pages/search/:q': 'search',
    'pages/:id':       'show'
  },
  initialize: function() {
    console.log('initialize');
  },
  index: function()        { /* code */ },
  search: function(query) { /* code */ },
  show: function(id) { /* code */ }
});

var app = new AppRouter();

Backbone.history.start();
var AppRouter = Backbone.Router.extend({
  routes: {
    'pages':         'index',
    'pages/search/:q': 'search',
    'pages/:id':       'show'
  },
  initialize: function() {
    console.log('initialize');
  },
  index: function()        { /* code */ },
  search: function(query) { /* code */ },
  show: function(id) { /* code */ }
});

var app = new AppRouter();

Backbone.history.start();
var AppRouter = Backbone.Router.extend({
  routes: {
    'pages':         'index',
    'pages/search/:q': 'search',
    'pages/:id':       'show'
  },
  initialize: function() {
    console.log('initialize');
  },
  index: function()        { /* code */ },
  search: function(query) { /* code */ },
  show: function(id) { /* code */ }
});

var app = new AppRouter();

Backbone.history.start();
var AppRouter = Backbone.Router.extend({
  routes: {
    'pages':         'index',
    'pages/search/:q': 'search',
    'pages/:id':       'show'
  },
  initialize: function() {
    console.log('initialize');
  },
  index: function()        { /* code */ },
  search: function(query) { /* code */ },
  show: function(id) { /* code */ }
});

var app = new AppRouter();

Backbone.history.start();
var AppRouter = Backbone.Router.extend({
  routes: {
    'pages':         'index',
    'pages/search/:q': 'search',
    'pages/:id':       'show'
  },
  initialize: function() {
    console.log('initialize');
  },
  index: function()        { /* code */ },
  search: function(query) { /* code */ },
  show: function(id) { /* code */ }
});

var app = new AppRouter();

Backbone.history.start();
app.navigate('pages', true);
app.navigate('pages/search/title', true);
app.navigate('pages/3', true);
site.com/path#pages
site.com/path#pages/search/title
site.com/path#pages/3
Backbone.history.start({pushState: true});
site.com/path#pages
site.com/path#pages/search/title
site.com/path#pages/3
site.com/path/pages
site.com/path/pages/search/title
site.com/path/pages/3
Недостатъци
Алтернативи
Алтернативи
Алтернативи
Алтернативи
Въпроси?
Благодаря за вниманието



@rstankov

More Related Content

What's hot

JavaScript Unit Testing with Jasmine
JavaScript Unit Testing with JasmineJavaScript Unit Testing with Jasmine
JavaScript Unit Testing with Jasmine
Raimonds Simanovskis
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
Daniel Knell
 
Min-Maxing Software Costs - Laracon EU 2015
Min-Maxing Software Costs - Laracon EU 2015Min-Maxing Software Costs - Laracon EU 2015
Min-Maxing Software Costs - Laracon EU 2015
Konstantin Kudryashov
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KThomas Fuchs
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
Anis Ahmad
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
Visual Engineering
 
Node.js in action
Node.js in actionNode.js in action
Node.js in action
Simon Su
 
Min-Maxing Software Costs
Min-Maxing Software CostsMin-Maxing Software Costs
Min-Maxing Software Costs
Konstantin Kudryashov
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Domenic Denicola
 
Decoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DICDecoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DIC
Konstantin Kudryashov
 
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby DeveloperVenturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Jon Kruger
 
5 Tips for Better JavaScript
5 Tips for Better JavaScript5 Tips for Better JavaScript
5 Tips for Better JavaScript
Todd Anglin
 
Testable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScriptTestable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScript
Jon Kruger
 
Dollar symbol
Dollar symbolDollar symbol
Dollar symbol
Aaron Huang
 
Crafting beautiful software
Crafting beautiful softwareCrafting beautiful software
Crafting beautiful software
Jorn Oomen
 
Frontin like-a-backer
Frontin like-a-backerFrontin like-a-backer
Frontin like-a-backer
Frank de Jonge
 
06 jQuery #burningkeyboards
06 jQuery  #burningkeyboards06 jQuery  #burningkeyboards
06 jQuery #burningkeyboards
Denis Ristic
 
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you needDutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Kacper Gunia
 
05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards
Denis Ristic
 
Workshop 8: Templating: Handlebars, DustJS
Workshop 8: Templating: Handlebars, DustJSWorkshop 8: Templating: Handlebars, DustJS
Workshop 8: Templating: Handlebars, DustJS
Visual Engineering
 

What's hot (20)

JavaScript Unit Testing with Jasmine
JavaScript Unit Testing with JasmineJavaScript Unit Testing with Jasmine
JavaScript Unit Testing with Jasmine
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
 
Min-Maxing Software Costs - Laracon EU 2015
Min-Maxing Software Costs - Laracon EU 2015Min-Maxing Software Costs - Laracon EU 2015
Min-Maxing Software Costs - Laracon EU 2015
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScript
 
Node.js in action
Node.js in actionNode.js in action
Node.js in action
 
Min-Maxing Software Costs
Min-Maxing Software CostsMin-Maxing Software Costs
Min-Maxing Software Costs
 
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 
Decoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DICDecoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DIC
 
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby DeveloperVenturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
 
5 Tips for Better JavaScript
5 Tips for Better JavaScript5 Tips for Better JavaScript
5 Tips for Better JavaScript
 
Testable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScriptTestable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScript
 
Dollar symbol
Dollar symbolDollar symbol
Dollar symbol
 
Crafting beautiful software
Crafting beautiful softwareCrafting beautiful software
Crafting beautiful software
 
Frontin like-a-backer
Frontin like-a-backerFrontin like-a-backer
Frontin like-a-backer
 
06 jQuery #burningkeyboards
06 jQuery  #burningkeyboards06 jQuery  #burningkeyboards
06 jQuery #burningkeyboards
 
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you needDutch PHP Conference - PHPSpec 2 - The only Design Tool you need
Dutch PHP Conference - PHPSpec 2 - The only Design Tool you need
 
05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards
 
Workshop 8: Templating: Handlebars, DustJS
Workshop 8: Templating: Handlebars, DustJSWorkshop 8: Templating: Handlebars, DustJS
Workshop 8: Templating: Handlebars, DustJS
 

Similar to Backbone js

Building Your First Widget
Building Your First WidgetBuilding Your First Widget
Building Your First Widget
Chris Wilcoxson
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说Ting Lv
 
JSGeneve - Backbone.js
JSGeneve - Backbone.jsJSGeneve - Backbone.js
JSGeneve - Backbone.js
Pierre Spring
 
JSDay Italy - Backbone.js
JSDay Italy - Backbone.jsJSDay Italy - Backbone.js
JSDay Italy - Backbone.jsPierre Spring
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
Nick Lee
 
AngularJs
AngularJsAngularJs
AngularJs
Hossein Baghayi
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
Jonathan Wage
 
Intro to Ember.JS 2016
Intro to Ember.JS 2016Intro to Ember.JS 2016
Intro to Ember.JS 2016
Sandino Núñez
 
TypeScriptで書くAngularJS @ GDG神戸2014.8.23
TypeScriptで書くAngularJS @ GDG神戸2014.8.23TypeScriptで書くAngularJS @ GDG神戸2014.8.23
TypeScriptで書くAngularJS @ GDG神戸2014.8.23
Okuno Kentaro
 
¿Cómo de sexy puede hacer Backbone mi código?
¿Cómo de sexy puede hacer Backbone mi código?¿Cómo de sexy puede hacer Backbone mi código?
¿Cómo de sexy puede hacer Backbone mi código?
jaespinmora
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node js
Francois Zaninotto
 
How to React Native
How to React NativeHow to React Native
How to React Native
Dmitry Ulyanov
 
jQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journeyjQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journey
Huiyi Yan
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
pootsbook
 
Real Time App with Node.js
Real Time App with Node.jsReal Time App with Node.js
Real Time App with Node.js
Jxck Jxck
 
Simple Web Apps With Sinatra
Simple Web Apps With SinatraSimple Web Apps With Sinatra
Simple Web Apps With Sinatraa_l
 

Similar to Backbone js (20)

Building Your First Widget
Building Your First WidgetBuilding Your First Widget
Building Your First Widget
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
 
JSGeneve - Backbone.js
JSGeneve - Backbone.jsJSGeneve - Backbone.js
JSGeneve - Backbone.js
 
JSDay Italy - Backbone.js
JSDay Italy - Backbone.jsJSDay Italy - Backbone.js
JSDay Italy - Backbone.js
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
 
AngularJs
AngularJsAngularJs
AngularJs
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
JavaScript patterns
JavaScript patternsJavaScript patterns
JavaScript patterns
 
Backbone Basics with Examples
Backbone Basics with ExamplesBackbone Basics with Examples
Backbone Basics with Examples
 
Django
DjangoDjango
Django
 
Intro to Ember.JS 2016
Intro to Ember.JS 2016Intro to Ember.JS 2016
Intro to Ember.JS 2016
 
TypeScriptで書くAngularJS @ GDG神戸2014.8.23
TypeScriptで書くAngularJS @ GDG神戸2014.8.23TypeScriptで書くAngularJS @ GDG神戸2014.8.23
TypeScriptで書くAngularJS @ GDG神戸2014.8.23
 
¿Cómo de sexy puede hacer Backbone mi código?
¿Cómo de sexy puede hacer Backbone mi código?¿Cómo de sexy puede hacer Backbone mi código?
¿Cómo de sexy puede hacer Backbone mi código?
 
Bonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node jsBonnes pratiques de développement avec Node js
Bonnes pratiques de développement avec Node js
 
How to React Native
How to React NativeHow to React Native
How to React Native
 
jQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journeyjQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journey
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
 
Real Time App with Node.js
Real Time App with Node.jsReal Time App with Node.js
Real Time App with Node.js
 
Angular Workshop_Sarajevo2
Angular Workshop_Sarajevo2Angular Workshop_Sarajevo2
Angular Workshop_Sarajevo2
 
Simple Web Apps With Sinatra
Simple Web Apps With SinatraSimple Web Apps With Sinatra
Simple Web Apps With Sinatra
 

Recently uploaded

Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 

Recently uploaded (20)

Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 

Backbone js

  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15. Browser Controller Model View Сървър
  • 16. Browser Controller Model View Сървър
  • 17. Browser Controller Model View Сървър
  • 18. Browser Controller Model View Сървър
  • 19. Browser Controller Model View Сървър
  • 20. Browser Controller Model View Сървър
  • 21. Browser Controller Model View Сървър
  • 22. Browser Controller Model View Сървър
  • 23. Browser Controller Model View Сървър
  • 24. Browser Controller Model View Сървър
  • 25. Browser Controller Model View Сървър
  • 26. Browser Controller Model View Сървър
  • 27. Browser Controller Model View Сървър
  • 38. var object = {}; $.extend(object, Backbone.Events); object.bind('eventName', function() { console.log('1'); }); object.bind('eventName', function() { console.log('2'); }); object.trigger('eventName'); // prints '1' and '2'
  • 39. var object = {}; $.extend(object, Backbone.Events); object.bind('eventName', function() { console.log('1'); }); object.bind('eventName', function() { console.log('2'); }); object.trigger('eventName'); // prints '1' and '2'
  • 40. var object = {}; $.extend(object, Backbone.Events); object.bind('eventName', function() { console.log('1'); }); object.bind('eventName', function() { console.log('2'); }); object.trigger('eventName'); // prints '1' and '2'
  • 41. var object = {}; $.extend(object, Backbone.Events); object.bind('eventName', function() { console.log('1'); }); object.bind('eventName', function() { console.log('2'); }); object.trigger('eventName'); // prints '1' and '2'
  • 42. var object = {}; $.extend(object, Backbone.Events); object.bind('eventName', function() { console.log('1'); }); object.bind('eventName', function() { console.log('2'); }); object.trigger('eventName'); // prints '1' and '2'
  • 44. var Person = Backbone.Model.extend({ initialize: function(){ console.log("I'm alive!"); } }); new Person();
  • 45. var Person = Backbone.Model.extend({ initialize: function(){ console.log("I'm alive!"); } }); new Person();
  • 46. var Person = Backbone.Model.extend({ initialize: function(){ console.log("I'm alive!"); } }); new Person();
  • 47. var Person = Backbone.Model.extend({}); var me = new Person({name: 'Radoslav'}); me.get('name'); // Radoslav me.set({lastName: 'Stankov'}); me.get('lastName'); // Stankov
  • 48. var Person = Backbone.Model.extend({}); var me = new Person({name: 'Radoslav'}); me.get('name'); // Radoslav me.set({lastName: 'Stankov'}); me.get('lastName'); // Stankov
  • 49. var Person = Backbone.Model.extend({}); var me = new Person({name: 'Radoslav'}); me.get('name'); // Radoslav me.set({lastName: 'Stankov'}); me.get('lastName'); // Stankov
  • 50. var Person = Backbone.Model.extend({}); var me = new Person({name: 'Radoslav'}); me.get('name'); // Radoslav me.set({lastName: 'Stankov'}); me.get('lastName'); // Stankov
  • 51. var Person = Backbone.Model.extend({}); var me = new Person({name: 'Radoslav'}); me.get('name'); // Radoslav me.set({lastName: 'Stankov'}); me.get('lastName'); // Stankov
  • 52. var Person = Backbone.Model.extend({ defaults: { name: 'John', lastName: 'Doe', } }); var me = new Person(); me.get('name'); // John me.get('lastName'); // Doe
  • 53. var Person = Backbone.Model.extend({ defaults: { name: 'John', lastName: 'Doe', } }); var me = new Person(); me.get('name'); // John me.get('lastName'); // Doe
  • 54. var Person = Backbone.Model.extend({ defaults: { name: 'John', lastName: 'Doe', } }); var me = new Person(); me.get('name'); // John me.get('lastName'); // Doe
  • 55. var Person = Backbone.Model.extend({ defaults: { name: 'John', lastName: 'Doe', } }); var me = new Person(); me.get('name'); // John me.get('lastName'); // Doe
  • 56. var Calculator = Backbone.Model.extend({ defaults: { value: 0 }, value: function(){ return this.get('value'); }, sum: function(value){ this.set({value: value + this.get('value')}); }, reset: function(){ this.set({value: 0}); } });
  • 57. var Calculator = Backbone.Model.extend({ defaults: { value: 0 }, value: function(){ return this.get('value'); }, sum: function(value){ this.set({value: value + this.get('value')}); }, reset: function(){ this.set({value: 0}); } });
  • 58. var Calculator = Backbone.Model.extend({ defaults: { value: 0 }, value: function(){ return this.get('value'); }, sum: function(value){ this.set({value: value + this.get('value')}); }, reset: function(){ this.set({value: 0}); } });
  • 59. var Calculator = Backbone.Model.extend({ defaults: { value: 0 }, value: function(){ return this.get('value'); }, sum: function(value){ this.set({value: value + this.get('value')}); }, reset: function(){ this.set({value: 0}); } });
  • 60. var Calculator = Backbone.Model.extend({ defaults: { value: 0 }, value: function(){ return this.get('value'); }, sum: function(value){ this.set({value: value + this.get('value')}); }, reset: function(){ this.set({value: 0}); } });
  • 61. var cal = new Calculator(); cal.bind('change:value', function(model, value){ console.log(value); }); cal.bind('change', function(model){ console.log(model.get('value')); }); cal.bind('all', function(eventName) { console.log('I see every thing!', eventName); });
  • 62. var cal = new Calculator(); cal.bind('change:value', function(model, value){ console.log(value); }); cal.bind('change', function(model){ console.log(model.get('value')); }); cal.bind('all', function(eventName) { console.log('I see every thing!', eventName); });
  • 63. var cal = new Calculator(); cal.bind('change:value', function(model, value){ console.log(value); }); cal.bind('change', function(model){ console.log(model.get('value')); }); cal.bind('all', function(eventName) { console.log('I see every thing!', eventName); });
  • 64. var cal = new Calculator(); cal.bind('change:value', function(model, value){ console.log(value); }); cal.bind('change', function(model){ console.log(model.get('value')); }); cal.bind('all', function(eventName) { console.log('I see every thing!', eventName); });
  • 65. var cal = new Calculator(); cal.bind('myEvent', function(){ console.log('KaBoom....'); }); cal.trigger('myEvent');
  • 66. var Product = Backbone.Model.extend({ urlRoot: '/products' }); var chair = new Product({ name: 'chair', price: 10 }); chair.save(); // POST /products
  • 67. var Product = Backbone.Model.extend({ url: function(){ return '/products/' + (this.isNew() ? '' : this.id); } }); var chair = new Product({ id: 5, name: 'chair', price: 10 }); chair.save(); // PUT /products/1
  • 69. И още... • validate • escape • has • unset • clear • hasChanged • changedAttributes • previousAttributes • fetch • toJSON • clone
  • 71.
  • 72. var UserNameView = Backbone.View.extend({ tagName: 'input', className: 'string optional', id: 'user-name', attributes: { type: 'string', name: 'user[name]' } }); var userName = new UserNameView(); console.log(userName.el); <input type="string" name="user[name]" id="user-name" class="string optional">
  • 73. var UserNameView = Backbone.View.extend({ tagName: 'input', className: 'string optional', id: 'user-name', attributes: { type: 'string', name: 'user[name]' } }); var userName = new UserNameView(); console.log(userName.el); <input type="string" name="user[name]" id="user-name" class="string optional">
  • 74. var UserNameView = Backbone.View.extend({ tagName: 'input', className: 'string optional', id: 'user-name', attributes: { type: 'string', name: 'user[name]' } }); var userName = new UserNameView(); console.log(userName.el); <input type="string" name="user[name]" id="user-name" class="string optional">
  • 75. var UserNameView = Backbone.View.extend({ tagName: 'input', className: 'string optional', id: 'user-name', attributes: { type: 'string', name: 'user[name]' } }); var userName = new UserNameView(); console.log(userName.el); <input type="string" name="user[name]" id="user-name" class="string optional">
  • 76. var UserNameView = Backbone.View.extend({ tagName: 'input', className: 'string optional', id: 'user-name', attributes: { type: 'string', name: 'user[name]' } }); var userName = new UserNameView(); console.log(userName.el); <input type="string" name="user[name]" id="user-name" class="string optional">
  • 77. var UserNameView = Backbone.View.extend({ tagName: 'input', className: 'string optional', id: 'user-name', attributes: { type: 'string', name: 'user[name]' } }); var userName = new UserNameView(); console.log(userName.el); <input type="string" name="user[name]" id="user-name" class="string optional">
  • 78. var UserNameView = Backbone.View.extend({ tagName: 'input', className: 'string optional', id: 'user-name', attributes: { type: 'string', name: 'user[name]' } }); var userName = new UserNameView(); console.log(userName.el); <input type="string" name="user[name]" id="user-name" class="string optional">
  • 79. var UsersListView = Backbone.View.extend({ el: '#users-list' }); var userList = new UsersListView(); console.log(userList.el);
  • 80. var EditBoxView = Backbone.View.extend({}); var element = $('#edit-box-view').get(0), editBox = new EditBoxView({el: element}); console.log(editBox.el === element);
  • 81. var DocumentView = Backbone.View.extend({ events: { 'dblclick': 'open', 'click .grid .doc': 'select', 'customEvent .title': 'custom' }, open: function() {}, select: function() {}, custom: function() {} });
  • 82. var DocumentView = Backbone.View.extend({ events: { 'dblclick': 'open', 'click .grid .doc': 'select', 'customEvent .title': 'custom' }, open: function() {}, select: function() {}, custom: function() {} });
  • 83. var DocumentView = Backbone.View.extend({ events: { 'dblclick': 'open', 'click .grid .doc': 'select', 'customEvent .title': 'custom' }, open: function() {}, select: function() {}, custom: function() {} });
  • 84. var DocumentView = Backbone.View.extend({ events: { 'dblclick': 'open', 'click .grid .doc': 'select', 'customEvent .title': 'custom' }, open: function() {}, select: function() {}, custom: function() {} });
  • 85. var DocumentView = Backbone.View.extend({ events: { 'dblclick': 'open', 'click .grid .doc': 'select', 'customEvent .title': 'custom' }, open: function() {}, select: function() {}, custom: function() {} });
  • 86. var DocumentView = Backbone.View.extend({ events: { 'dblclick': 'open', 'click .grid .doc': 'select', 'customEvent .title': 'custom' }, open: function() {}, select: function() {}, custom: function() {} });
  • 87. var DocumentView = Backbone.View.extend({ events: { 'dblclick': 'open', 'click .grid .doc': 'select', 'customEvent .title': 'custom' }, open: function() {}, select: function() {}, custom: function() {} });
  • 88. <script type="text/template" id="news"> <h1><%= title %></h1> <time><%= created_at %></time> <p><%= text %></p> </script>
  • 89. var NewsView = Backbone.View.extend({ template: _.template($('#news').html()), render: function() { this.el.innerHTML = this.template(this.model); return this; } });
  • 90. var view = new NewsView({ model: { title: "News Title", created_at: "Today", text: "Long text" } }); document.body.appendChild(view.render().el);
  • 91. <script type="text/template" id="news"> <h1><%= title %></h1> <time><%= created_at %></time> <p><%= text %></p> </script>
  • 92. <div> <h1>News Title</h1> <time>Today</time> <p>Long text</p> </div>
  • 93. View Model DOM
  • 94. View Model DOM
  • 95. View Model DOM
  • 96. View Model DOM
  • 97. View Model DOM
  • 98. View Model DOM
  • 99. View Model DOM
  • 100. View Model DOM
  • 101. View Model DOM
  • 102. View Model DOM
  • 103. View Model DOM View 2
  • 104. View Model DOM View 2
  • 105. View Model DOM View 2
  • 106. View Model DOM View 2
  • 107. View Model DOM View 2
  • 108. View Model DOM View 2
  • 109. View Model DOM View 2
  • 110. View Model DOM View 2
  • 111. View Model DOM View 2
  • 112. View Model DOM View 2
  • 113. View View 2 Model DOM
  • 114. View View 2 Model DOM View 3
  • 115. View View 2 Model DOM View 3 View 4
  • 116. View View 2 Model DOM View 3 View 4 View .. N
  • 117. View View 2 Model DOM View 3 View 4 View .. N
  • 118. View View 2 Model DOM View 3 View 4 View .. N
  • 119. View View 2 Model DOM View 3 View 4 View .. N
  • 120. View View 2 Model DOM View 3 View 4 View .. N
  • 121. View View 2 Model DOM View 3 View 4 View .. N
  • 122. View View 2 Model DOM View 3 View 4 View .. N
  • 123. View View 2 Model DOM View 3 View 4 View .. N
  • 124. View View 2 Model DOM View 3 View 4 View .. N
  • 125. Demo
  • 126. var Calculator = Backbone.Model.extend({ defaults: { value: 0 }, increment: function() { this.set({'value': this.get('value') + 1}); }, decrement: function() { this.set({'value': this.get('value') - 1}); }, getValue: function() { return this.get('value'); } });
  • 127. var ButtonsView = Backbone.View.extend({ events: { 'click .plus': 'plus', 'click .minus': 'minus' }, plus: function() { this.model.increment(); }, minus: function() { this.model.decrement(); } });
  • 128. var DisplayView = Backbone.View.extend({ initialize: function() { this.model.bind('change:value', this.render, this); this.render(); }, render: function() { this.el.innerHTML = this.model.getValue(); return this; } });
  • 129. var cal = new Calculator(); new ButtonsView({model: cal, el: '.buttons'}); new DisplayView({model: cal, el: '.display'});
  • 131. var ProductsCollection = Backbone.Collection.extend({ model: Product }); var products = new ProductsCollection(); products.fetch(); products.bind('reset', function(list) { console.log('Loaded', list.length, 'records'); });
  • 132. products.bind('add', function(model) { console.log('new product added'); }); products.bind('remove', function(model) { console.log('item product removed'); });
  • 133. И още... • Underscore Methods • add / remove / at • sort / comparator • reset • create • url • toJSON
  • 135.
  • 136. var AppRouter = Backbone.Router.extend({ routes: { 'pages': 'index', 'pages/search/:q': 'search', 'pages/:id': 'show' }, initialize: function() { console.log('initialize'); }, index: function() { /* code */ }, search: function(query) { /* code */ }, show: function(id) { /* code */ } }); var app = new AppRouter(); Backbone.history.start();
  • 137. var AppRouter = Backbone.Router.extend({ routes: { 'pages': 'index', 'pages/search/:q': 'search', 'pages/:id': 'show' }, initialize: function() { console.log('initialize'); }, index: function() { /* code */ }, search: function(query) { /* code */ }, show: function(id) { /* code */ } }); var app = new AppRouter(); Backbone.history.start();
  • 138. var AppRouter = Backbone.Router.extend({ routes: { 'pages': 'index', 'pages/search/:q': 'search', 'pages/:id': 'show' }, initialize: function() { console.log('initialize'); }, index: function() { /* code */ }, search: function(query) { /* code */ }, show: function(id) { /* code */ } }); var app = new AppRouter(); Backbone.history.start();
  • 139. var AppRouter = Backbone.Router.extend({ routes: { 'pages': 'index', 'pages/search/:q': 'search', 'pages/:id': 'show' }, initialize: function() { console.log('initialize'); }, index: function() { /* code */ }, search: function(query) { /* code */ }, show: function(id) { /* code */ } }); var app = new AppRouter(); Backbone.history.start();
  • 140. var AppRouter = Backbone.Router.extend({ routes: { 'pages': 'index', 'pages/search/:q': 'search', 'pages/:id': 'show' }, initialize: function() { console.log('initialize'); }, index: function() { /* code */ }, search: function(query) { /* code */ }, show: function(id) { /* code */ } }); var app = new AppRouter(); Backbone.history.start();
  • 141. var AppRouter = Backbone.Router.extend({ routes: { 'pages': 'index', 'pages/search/:q': 'search', 'pages/:id': 'show' }, initialize: function() { console.log('initialize'); }, index: function() { /* code */ }, search: function(query) { /* code */ }, show: function(id) { /* code */ } }); var app = new AppRouter(); Backbone.history.start();
  • 142. var AppRouter = Backbone.Router.extend({ routes: { 'pages': 'index', 'pages/search/:q': 'search', 'pages/:id': 'show' }, initialize: function() { console.log('initialize'); }, index: function() { /* code */ }, search: function(query) { /* code */ }, show: function(id) { /* code */ } }); var app = new AppRouter(); Backbone.history.start();
  • 143. var AppRouter = Backbone.Router.extend({ routes: { 'pages': 'index', 'pages/search/:q': 'search', 'pages/:id': 'show' }, initialize: function() { console.log('initialize'); }, index: function() { /* code */ }, search: function(query) { /* code */ }, show: function(id) { /* code */ } }); var app = new AppRouter(); Backbone.history.start();
  • 144. var AppRouter = Backbone.Router.extend({ routes: { 'pages': 'index', 'pages/search/:q': 'search', 'pages/:id': 'show' }, initialize: function() { console.log('initialize'); }, index: function() { /* code */ }, search: function(query) { /* code */ }, show: function(id) { /* code */ } }); var app = new AppRouter(); Backbone.history.start();
  • 145. var AppRouter = Backbone.Router.extend({ routes: { 'pages': 'index', 'pages/search/:q': 'search', 'pages/:id': 'show' }, initialize: function() { console.log('initialize'); }, index: function() { /* code */ }, search: function(query) { /* code */ }, show: function(id) { /* code */ } }); var app = new AppRouter(); Backbone.history.start();
  • 146. var AppRouter = Backbone.Router.extend({ routes: { 'pages': 'index', 'pages/search/:q': 'search', 'pages/:id': 'show' }, initialize: function() { console.log('initialize'); }, index: function() { /* code */ }, search: function(query) { /* code */ }, show: function(id) { /* code */ } }); var app = new AppRouter(); Backbone.history.start();
  • 149.
  • 153.
  • 154.
  • 155.
  • 156.
  • 157.
  • 158.
  • 159.

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. \n
  90. \n
  91. \n
  92. \n
  93. \n
  94. \n
  95. \n
  96. \n
  97. \n
  98. \n
  99. \n
  100. \n
  101. Open-Close prinsible - open for extensions, close for modifications\n\n
  102. Open-Close prinsible - open for extensions, close for modifications\n\n
  103. Open-Close prinsible - open for extensions, close for modifications\n\n
  104. Open-Close prinsible - open for extensions, close for modifications\n\n
  105. Open-Close prinsible - open for extensions, close for modifications\n\n
  106. Open-Close prinsible - open for extensions, close for modifications\n\n
  107. Open-Close prinsible - open for extensions, close for modifications\n\n
  108. Open-Close prinsible - open for extensions, close for modifications\n\n
  109. Open-Close prinsible - open for extensions, close for modifications\n\n
  110. Open-Close prinsible - open for extensions, close for modifications\n\n
  111. Open-Close prinsible - open for extensions, close for modifications\n\n
  112. Open-Close prinsible - open for extensions, close for modifications\n\n
  113. \n
  114. \n
  115. \n
  116. \n
  117. \n
  118. \n
  119. \n
  120. \n
  121. \n
  122. \n
  123. \n
  124. \n
  125. \n
  126. \n
  127. \n
  128. \n
  129. \n
  130. \n
  131. \n
  132. \n
  133. \n
  134. \n
  135. \n
  136. \n
  137. \n
  138. \n
  139. \n
  140. \n
  141. \n
  142. \n
  143. \n
  144. \n
  145. \n
  146. \n
  147. \n
  148. \n
  149. \n
  150. \n
  151. \n