3

I have this:

function test()
{
    this.method = function ()
                {
                    $("html").mousemove(function(event) {
                        console.log('~> moved');
                    });
                }
    this.method();
}

testInstance = new test();

testInstance = null;  // delete window.testInstace;

Although I have removed references to the object by setting testInstance to null (I've also tried deleting it as a property of window), the mousemove event handler continues to operate and write to the console. If deleting the object that established the event handler doesn't remove it what then should I do to remove the event handler?

nnnnnn
  • 147,572
  • 30
  • 200
  • 241
Michael
  • 4,786
  • 11
  • 45
  • 68

2 Answers2

17

if you are using jquery 1.7

$('html').off('mousemove');

else

$('html').unbind('mousemove');
Abbas
  • 6,720
  • 4
  • 35
  • 49
3

Destroying the object will not have any effect on the event handler that you've added. In order to remove the event handler, you need to unbind the event.

Jordan Ryan Moore
  • 6,877
  • 2
  • 26
  • 27