我正在尝试了解他们在 Backbone 0.9.9 中所做的新更改。
listenTo
目前我在理解和之间的区别时遇到了问题on
:
听
var View = Backbone.View.extend({
tagName: "div",
intialize: function() {
this.listenTo(this.model, 'change', this.render);
},
render: function() {
this.$el.empty();
this.$el.append('<p>hello world</p>');
}
});
在
var View = Backbone.View.extend({
tagName: "div",
intialize: function() {
this.model.on('change', this.render, this);
},
render: function() {
this.$el.empty();
this.$el.append('<p>hello world</p>');
}
});
我听说当视图被删除以避免内存泄漏时,它listenTo
允许stopListening
取消订阅所有事件。
这是唯一的原因吗?