Thursday, November 26, 2015

Backbone.Model

Models  contains the interactive data and the logic surrounding it, such as data validation, getters and setters, default values, data initialization, conversions .

following code creates model with 2 instance variables  title and completed
var app = {}; // create namespace for our app

    app.Todo = Backbone.Model.extend({
      defaults: {
        title: '',
        completed: false
      }
    });

execute following in browser console 
var todo = new app.Todo({title: 'Learn Backbone.js', completed: false}); // create object with the attributes specified.
todo.get('title'); // "Learn Backbone.js" 

No comments:

Post a Comment