var Foo = (function(){
function Foo(){
this._s="string";
this.setButton();
};
Foo.prototype.setButton = function(){
document.getElementById('id').addEventListener('click', function(event) {
alert(this._s);
});
};
Foo.prototype.method = function(){
alert(this._s);
};
return Foo;
})();
var fo = new Foo();
fo.method();
I want to bind an event to a button, and execute a function whic use a 'private' var, when I click the button the function is correctly called but it can't see the var this._s (it writes 'undefined'). If I write fo.method() the string is correctly printed. here is the jsfiddle: http://jsfiddle.net/wLm1v4La/1/