Volání metody z obsluhy události

Mám tento kód, na kterém pracuji, ale pokaždé, když zavolám metodu init, stále dostávám chybu:

this.addElement není funkce

Je to proto, že nemohu volat metody z obslužných rutin událostí?

function editor () {

    this.init = function () {
        $("#area").bind('click' , this.click_event );
        
    }

    this.addElement = function () {
        console.log("adding element");
    }

    this.click_event = function(event) {
        this.addElement();
        console.log("click event in x : "+event.data);
    }
}

Odpověď

function editor () {
    var that = this;

    this.init = function () {
        $("#area").bind('click' , this.click_event );

    }

    this.addElement = function () {
        console.log("adding element");
    }

    this.click_event = function(event) {
        that.addElement();
        console.log("click event in x : "+event.data);
    }
}

Měli byste si přečíst tuto knihu, JavaScript:The Good Parts a navštívit webovou stránku Crockenator zde, crockford.com

Můžete si také přečíst o problému JavaScriptu „toto“ zde, http://www.quirksmode.org/js/this.html