tags:

views:

25

answers:

1

how can i call stopEvent within init?

testObj.prototype =
{
    init: function(wrapper)
    {       
        wrapper.onclick = function(e){
            stopEvent(e);  //getting error stopEvent not defined
        };
    },
    stopEvent: function(e){
        if(e.preventDefault)
            e.preventDefault();
        else
            e.returnValue = false
    }
}
+2  A: 

You could capture this:

init: function(wrapper) {       
    var _this = this;
    wrapper.onclick = function(e) {
        _this.stopEvent(e);
    };
}
Darin Dimitrov
Correct solutions
Cédric Boivin