oscurodrago oscurodrago - 5 months ago 7
Javascript Question

Jquery .click() get superior this

Inside a method of my class I have:

this.background.click(function() {
this.terminate();
});


Obviously
this.terminate();
doesn't work because
this
refers to
this.background
inside
jquery.click
function. How do I have to write for get
this
from superior class?

Answer

Declare a variable containing the outer this:

var self = this;
this.background.click(function() {
    self.terminate();
});
Comments