0
I looked for a script to perform a function only once and found the function below
var something = (function() {
var executed = false;
return function () {
if (!executed) {
executed = true;
alert("olá");
}
};
})();
<a href="#" onclick="something()">Executar</a>
Well, it works perfectly!
But I do not understand why so much code since I summarized it in this way and also works perfectly
var executada = false;
function chama() {
if (!executada) {
executada = true;
alert("olá");
}
};
<a href="#" onclick="chama()">Executar</a>
Any specific reason in the first code?
There is someone chasing me downvoto on everything that is of my own making!! unfortunate this. What’s wrong with my question? This type of conduct does not add anything useful to the purpose of the site.
– user60252