User Tools

Site Tools


technical_notes:public:20130929-how-to-extend-backbone-class

Parent

Backbone - How to extend a class ?

You can use the class method when you want to implements a view for exemple :

app.ArtworksView = Backbone.View.extend({
  el:'#content',
  events: {
  },
 
  initialize: function(options) {     
    this.model = options.artworksCollection;
    this.listenTo(this.model, "add", this.render);
    this.listenTo(this.model, "remove", this.render);
  },
  render: function() 
  {
    return this;
  }   
});

If you want to add a method to all your backbone view you can use prototype :

Backbone.View.prototype.close = function() {
  // Implements your function
};

You can create a new callback to emulate some events and authorize your code modularization as you will do in C# :

Backbone.View.prototype.close = function() {
  if (this.onClose){
    this.onClose();
  }
};
technical_notes/public/20130929-how-to-extend-backbone-class.txt · Last modified: 2013/10/06 18:42 by Fabien Arcellier