我正在学习code sample of es6 with Backbone。我对以下代码感到困惑:
class TodoView extends View {
constructor(options) {
this.tagName = 'li';
this.template = _.template($('#item-template').html());
this.input = '';
this.events = {
'click .toggle': 'toggleCompleted',
'dbclick label': 'edit',
'click .destroy': 'clear',
'keypress .edit': 'updateOnEnter',
'blur .edit': 'close'
};
super(options);
this.listenTo(this.model, 'change', this.render);
this.listenTo(this.model, 'destroy', this.remove);
this.listenTo(this.model, 'visible', this.toggleVisible);
}
我有一些问题:
1,super(options)
的位置是否重要?
2,我应该将this.listenTo()
移至initialize()
吗?
3,following codes怎么样?
constructor() {
super({
tagName: 'li',
template: _.template(todosTemplate),
events: {
'click .toggle': 'toggleCompleted',
'dblclick label': 'edit',
'click .destroy': 'clear',
'keypress .edit': 'updateOnEnter',
'keydown .edit': 'revertOnEscape',
'blur .edit': 'close'
},
});
}