I have the following js code snippet:
var myloop=function(element){
...
var myValue;
element.onClick(){
//GET the first value of variable "myValue"
};
};
myloop.start();
When myloop
started, the body of myloop
function will be executed serverl times and the local variable myValue
will be updated each time myloop
has been run.
Inside myloop
function, I have an event handler element.onClick()
, this event handler is only interested in the first updated value of local variable myValue
.
I would like to ask some proposal of the most efficient way to get the first updated value of myValue
inside the handler.
My implementation is to define a index
and a Array
outside myloop
function , and store all the updated values inside the array, then in the handler, I get the first element from the array which is the first updated value of myValue
. But I don't this this is efficient, since the rest updated value in the array is useless.
So, anybody can give some other proposal to get the first updated value of myValue
inside the handler.