I want create an handler 'click' from a Javascript class and attach it to a simple button.
I created a simple Javascript class :
// from ./myclass.js
class Myclass
{
constructor()
{
$("input.showAlert").bind("click", this._showAlert());
}
_showAlert(e){
alert("foo");
}
}
module.exports = {
Myclass
};
And from my main js file :
// from ./main.js
const { Myclass } = require("./myclass");
var faa = new Myclass();
But if I do that, when I load my page via a browser, the alert "foo" appears automatically. I don't understand why and I don't want the alert is displaying automatically, but only when I click on the button 'input.addButton'.
My (very) simple html file :
<input class="showAlert" />
Where is my mistake ?