calling a method from an event handler

Posted by Ayoub on Stack Overflow See other posts from Stack Overflow or by Ayoub
Published on 2010-06-17T15:56:43Z Indexed on 2010/06/17 16:03 UTC
Read the original article Hit count: 249

I have this code i am working on but every time i call init method I keep getting an error

this.addElement is not a function

is it because i can't call methods from event handlers ?

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);
    }
}

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery