Question

is it possible to call a class method from within an event handler? I mean, something like this:

initialize: function(options) {
    /* initial options */
    this.setOptions(options);
    this.area = (this.options.status == 'out') ? $(this.options.loggedoutArea) : $(this.options.loggedinArea);
    this.button = $(this.options.buttonArea);
    this.button.addEvent('click', function(){
        this.showHideBanner();
    });       
},

showHideBanner: function() {
    this.area.setStyle('display', 'none');
},   

see full example here http://jsfiddle.net/dvzj6/

Was it helpful?

Solution

I managed to find a solution using this code:

initialize: function(options) {
    /* initial options */
    this.setOptions(options);
    this.area = (this.options.status == 'out') ? $(this.options.loggedoutArea) :     $(this.options.loggedinArea);
    this.button = $(this.options.buttonArea);
    this.button.addEvent('click', function(){
        this.showHideBanner();
    }.bind(this));       
},

see also: http://jsfiddle.net/uA3Ak/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top