OOP Javascript,将单击处理程序附加到构造函数中的按钮无法正常工作

OOP Javascript,将单击处理程序附加到构造函数中的按钮无法正常工作,javascript,jquery,oop,Javascript,Jquery,Oop,我想从Javascript类创建一个处理程序“click”,并将其附加到一个简单的按钮上 我创建了一个简单的Javascript类: // from ./myclass.js class Myclass { constructor() { $("input.showAlert").bind("click", this._showAlert()); } _showAlert(e){ alert("foo"); } } mod

我想从Javascript类创建一个处理程序“click”,并将其附加到一个简单的按钮上

我创建了一个简单的Javascript类:

// from ./myclass.js
class Myclass
{
    constructor()
    {
        $("input.showAlert").bind("click", this._showAlert());
    }
    _showAlert(e){
        alert("foo");
    }
}

module.exports = {
    Myclass
};
从我的主js文件:

// from ./main.js
const { Myclass } = require("./myclass");
var faa = new Myclass();
但如果我这样做,当我通过浏览器加载页面时,警报“foo”会自动出现。我不明白为什么,也不希望警报自动显示,但仅当我单击“input.addButton”按钮时

我的(非常)简单html文件:

<input class="showAlert" />


我的错在哪里

你不应该在这里给你的朋友打电话

$(“input.showAlert”).bind(“单击”,this.\u showAlert())

只需将此方法的链接传递为:


$(“input.showAlert”).bind(“单击”,this.\u showAlert)

你不应该在这里给你的方法打电话

$(“input.showAlert”).bind(“单击”,this.\u showAlert())

只需将此方法的链接传递为:


$(“input.showAlert”).bind(“单击”,this.\u showAlert)

通过编写
this.\u showart()
您可以立即调用函数,尝试
this.\u showart
通过编写
this.\u showart()
您可以立即调用函数,尝试
this.\u showart()
this.\u showart()
bind
已被弃用了大约10年,考虑<代码> .<代码> > .SavaRealTebug()>代码> .BION/CODE>已经被否决了10类,请考虑<代码>。在< /代码>谢谢!那太蠢了,哈哈,谢谢你!那太蠢了哈哈