How to create an object in JS once and for all? That is, when I click the mouse, I need to create an object and call a method, then if I click again, I need to use the same object.

Closed due to the fact that the essence of the question is not clear to the participants Cheg , Darth , αλεχολυτ , Suvitruf , Bald 10 Oct '17 at 6:27 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • four
    Create it outside the "click" event? - MoJlo4HuK

1 answer 1

You need to create an object outside the click event handling function. In the processing function, check whether the object has already been created. If not, create it.

let obj; function onclick(){ if(obj === undefined){ obj = новый объект; } используем obj }