我有简单的视图,显示对话框。为什么Backbone.View对象仍然保留在内存中?
Backbone.View.prototype.completeRemove = function(){
this.undelegateEvents();
this.remove();
delete this.$el;
delete this.el;
console.log('completely removed')
}
MdApp.dialogBox = Backbone.View.extend({
defaults: {
text: __('No text provided'),
buttonText: __('Ok'),
callback: function(){
return null;
},
el: $('#app-panel'),
type: 'error',
cancellable: false,
cancelText: __('No'),
picture: pic('default')
},
el: '<div class="dialog-box">',
template: _.template($('#dialog-box-template').html()),
events: {
'click .confirm' : 'confirm',
'click .cancel' : 'cancel'
},
initialize: function(){
this.model = _.extend(this.defaults, this.model);
this.render();
},
render: function(){
var model = this.model;
this.$el.html(this.template(model));
model.el.append(this.el);
},
confirm: function(){
var model = this.model;
var view = this;
this.completeRemove();
model.callback();
},
cancel: function(){
this.completeRemove();
}
});
它有它自己的默认值。每次我初始化新对话框时,它的值在每次对话框调用之间都会持续存在。例如,当我调用对话首次:
new MdApp.dialogBox({model:{
text: __('Do you really wanna delete this?'),
buttonText: __('Unfortunately yes'),
callback: function(){
//some callback
},
cancellable: true,
cancelText: __('No'),
picture: pic('confirm delete')
}});
在那之后,我调用另一个对话框,不cancellable
属性,因此它应该使用默认的(这是false
),但它保持真实。这适用于所有其他财产。为什么会发生?