function Foo(elementId, buttonId) {
this.element = document.getElementById(elementId);
this.button = document.getElementById(buttonId);
this.bar = function() {dosomething};
this.button.addEventListener('click', function(e) {this.bar();}, false);
}
var myFoo = new Foo('someElement', 'someButton');
我想在我的构造函数中添加事件侦听器,但它似乎不起作用。使用正确的语法可以做到这一点吗?我总是挂断电话:
this.button.addEventListener('click', function(e) {this.bar();}, false);