Skip to content

Step 2 - Contact Model

Compare
Choose a tag to compare
@dmytroyarmak dmytroyarmak released this 03 Feb 07:30
  1. Add app.js file with main namespace

    window.ContactManager = {
    Models: {},
    Collections: {},
    Views: {}
    };
    
  2. Add models/contact.js with empty model:

    ContactManager.Models.Contact = Backbone.Model.extend({
    });
    

    and to index.html:

    <script src="app/js/models/contact.js"></script>
    
  3. Show initialization, accessors, toJSON in console

  4. Add defaults to contact model:

    defaults: {
      name: null,
      tel: null,
      email: null,
      avatar: null
    }
    
  5. Add random avatar generation:

    initialize: function() {
      this.set('avatar', _.random(1, 15) + '.jpg');
    }
    
  6. Create some method and show in DevTools

Difference