SlideShare ist ein Scribd-Unternehmen logo
1 von 166
Радослав Станков
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

Weitere ähnliche Inhalte

Was ist angesagt?

JavaScript Unit Testing with Jasmine
JavaScript Unit Testing with JasmineJavaScript Unit Testing with Jasmine
JavaScript Unit Testing with JasmineRaimonds Simanovskis
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologyDaniel 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 2015Konstantin 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 beginningAnis Ahmad
 
Workshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptWorkshop 1: Good practices in JavaScript
Workshop 1: Good practices in JavaScriptVisual Engineering
 
Node.js in action
Node.js in actionNode.js in action
Node.js in actionSimon Su
 
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 DICKonstantin 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 DeveloperJon Kruger
 
5 Tips for Better JavaScript
5 Tips for Better JavaScript5 Tips for Better JavaScript
5 Tips for Better JavaScriptTodd Anglin
 
Testable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScriptTestable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScriptJon Kruger
 
Crafting beautiful software
Crafting beautiful softwareCrafting beautiful software
Crafting beautiful softwareJorn Oomen
 
06 jQuery #burningkeyboards
06 jQuery  #burningkeyboards06 jQuery  #burningkeyboards
06 jQuery #burningkeyboardsDenis 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 needKacper Gunia
 
05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboards05 JavaScript #burningkeyboards
05 JavaScript #burningkeyboardsDenis Ristic
 
Workshop 8: Templating: Handlebars, DustJS
Workshop 8: Templating: Handlebars, DustJSWorkshop 8: Templating: Handlebars, DustJS
Workshop 8: Templating: Handlebars, DustJSVisual Engineering
 

Was ist angesagt? (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
 

Ähnlich wie Backbone js

Building Your First Widget
Building Your First WidgetBuilding Your First Widget
Building Your First WidgetChris Wilcoxson
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说Ting Lv
 
JSGeneve - Backbone.js
JSGeneve - Backbone.jsJSGeneve - Backbone.js
JSGeneve - Backbone.jsPierre Spring
 
JSDay Italy - Backbone.js
JSDay Italy - Backbone.jsJSDay Italy - Backbone.js
JSDay Italy - Backbone.jsPierre Spring
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejsNick Lee
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For BeginnersJonathan Wage
 
TypeScriptで書くAngularJS @ GDG神戸2014.8.23
TypeScriptで書くAngularJS @ GDG神戸2014.8.23TypeScriptで書くAngularJS @ GDG神戸2014.8.23
TypeScriptで書くAngularJS @ GDG神戸2014.8.23Okuno 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 jsFrancois Zaninotto
 
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 journeyHuiyi 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 MVCpootsbook
 
Real Time App with Node.js
Real Time App with Node.jsReal Time App with Node.js
Real Time App with Node.jsJxck Jxck
 
Simple Web Apps With Sinatra
Simple Web Apps With SinatraSimple Web Apps With Sinatra
Simple Web Apps With Sinatraa_l
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 

Kürzlich hochgeladen (20)

E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 

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.

Hinweis der Redaktion

  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