请问在 end 中为何移除不了事件?
function counter (obj){
this.obj = obj;
this.num = 0;
}
counter.prototype.start = function(){
var self = this;
return function(){
self.obj.addEventListener( "mousemove" , self.move.apply(self,arguments) , false );
self.obj.addEventListener( "mouseup" , self.end.apply(self,arguments) , false );
}
}
counter.prototype.move = function(){
var self = this;
return function(){
document.title = self.num++;
}
}
counter.prototype.end = function(){
var self = this;
return function(){
// alert(self);
self.obj.removeEventListener( "mousemove" , self.move.apply(self,arguments) , false );
self.obj.removeEventListener( "mouseup" , self.end.apply(self,arguments) , false );
}
}
counter.prototype.init = function(){
var self = this;
// alert(this);
self.obj.addEventListener( "mousedown" , self.start.apply(self,arguments) , false );
}
var counterNew = new counter(document);
counterNew.init();
记住,解绑得和绑定是同一个函数