how to write a function passed as an argument in a constructor?
Hello Javascript Expert. Here is my problem. In my code, a constructor makes buttons. Each button have its own function. How to write paramaters inside object constructor (meaning how to assign onclick attribute) correctly ? for exemple, function 'moveleft' must be assigned to 'buttonLeft' // my button constructor: function buttonConstructor(param1,param2...,action){ this.param1=param1; ... this.action=action; this.commandCreate = function(){ var btn = document.createElement("button"); ... btn.setAttribute("onclick", action); //action is assigned to the onclick attribute }; // button creation buttonLeft = new buttonConstructor("param1",...,movleft); //how i should write moveleft function assigned to action?) // function being assigned to 'action' argument function moveleft() { myCar.speedX -= 1; } regards