I've got three interconnected methods inside an object:
dragStartHandler: function(e) {
console.log(e.type, 'dragstart', e.pageX, e.pageY);
document.addEventListener('mousemove', this.dragMoveHandler, false);
document.addEventListener('mouseup', this.dragEndHandler.bind(this), false);
},
dragMoveHandler: function(e) {
console.log(e.type, 'dragmove', e.pageX, e.pageY);
this.updateRotation();
},
dragEndHandler: function(e) {
console.log(e.type, 'dragend', e.pageX, e.pageY);
document.removeEventListener('mousemove', this.dragMoveHandler, false);
},
They handle rotation based on mouse pointer position. I can't figure out what to do to have access to original this
inside dragMoveHandler
and be able to remove the element listener at the same time.
I tried using .bind(this)
but it returns anonymous function which I can't remove inside dragEndHandler
.
Is there a technique I'm not aware of?