Your this value changes in the constructor. You can save the link in the selector and use the link.
function Foo(elementId, buttonId) { var self = this; this.button.addEventListener('click', function(e) {self.bar();}, false); }
Or a more modern solution that does not require a variable would use Function.prototype.bind .
function Foo(elementId, buttonId) { this.button.addEventListener('click', this.bar.bind(this), false); }
The .bind method returns a new bar function with the this value associated with the fact that you passed it. In this case, it is bound to the original this from the constructor.
source share