Backbone & ES2015

Easy win ou Epic fail ?

@florentduveau

dev chez Canal+

Pourquoi ça fonctionne un peu ?

class View extends Bacbone.View {

  constructor(props){
    super(props)
  }

}
Backbone.View est une function

View.prototype --> Backbone.View.prototype --> Object.prototype

new View();
var View = Backbone.View.extend({

  model: new WelcomeModel(),

  template: _.template(...),

  events: {
    'click #button': 'hideRedText',
  },

  initialize: function(){},

  ....

});
extend: function(protoProps){

  var parent = Backbone.view;
  var child = function(){ 
    return parent.apply(this, arguments); 
  };

  var Surrogate = function(){ this.constructor = child; };
  Surrogate.prototype = parent.prototype;
  child.prototype = new Surrogate;

  _.extend(child.prototype, protoPros); // OH !!

  return child;
}
new View();

// creation de cid

delegateEvents: function(events) {
   var events = _.result(this, 'events')); //OH NO !!
   ...
}

Pourquoi ça foire un peu ?

C'est donc mort ?

On fait quoi alors ?

  • On passe en ES2015 anyway
     
  • On utilise des decorators...
     
  • On attend une implémentation Backbone.

Des Questions ?

MERCI !

Backbone & ES2015

By Florent DUVEAU

Backbone & ES2015

  • 1,463