I have a problem with the onclick / addEventListener of javascript, I have already tried it in several different ways and none has resulted, I wanted my click event to be equal to a function already declared and not equal to an anonymous function, but I do not I'm able to do this cleanly in the code.
What I need is:
botao.onclick = criaObjeto(parametro);
function criaObjeto(parametro) {
//cria objeto
}
or
botao.addEventListener("click", criaObjeto(parametro));
function criaObjeto(parametro){
//cria objeto
}
Neither of these two ways worked, I would not really like to do something like this:
botao.onclick = function (){
criaObjeto(parametro);
)};
Because it breaks the idea of clean code, but none of the alternatives I tried worked, it just does not recognize the event. The click event happens as soon as the application starts and does not work later, so it does not work as a click, but rather as a normal function declared in the scope of the code.
The terminal does not trigger any errors at any time.