function cambiarPropiedades(elemento){
if(typeof control === "undefined"){
control = true; //No puedo usar el operador var
}
if(control == true){
//Código a ejecutar
control = false;
} else {
//Otro código a ejecutar
control = true;
}
}
I can not use the operator var
when defining control
because the code does not work because it creates a variable of local scope, and therefore, every time the function is executed and dies, it dies with it the variable and its value, so it would always enter the first if
and the result would always be the same.
I remember that when I gave some basic brush strokes in PHP they explained to me and I touched a bit the operator static
, which allowed to define a variable that is not destroyed when the function dies.
Is there any way to do something equivalent? In the example you can see that I have chosen to declare the variable control
as a global variable but I would like it not to be so, to avoid problems and out of pure curiosity. Nor does it convince me to call it _control to indicate its local scope and differentiate it. Is it possible?