Answer the question
In order to leave comments, you need to log in
Why is the variable not changing?
Hello. There is a code that blocks the execution of an action if 3 seconds have not passed.
Timer so to speak.
var socketEmitLastCallTime = 0;
var aqwsde = Date.now() - socketEmitLastCallTime ;
if(aqwsde >= 3 * 1000) {
socket.emit( 'message', { name: nameVal, message: msg, canal: canalVal } )
socketEmitLastCallTime = Date.now();
};
alert(aqwsde);
aqwsde
, and it deduces current time. Those. this variable socketEmitLastCallTime
is not stored. Why?
Answer the question
In order to leave comments, you need to log in
In connection with the clarifications:
Here is your function, for example, when you click on the button:
jsfiddle.net/iiil/FnbJn
You reset the socketEmitLastCallTime variable
each time. Accordingly, the click function works every time.
And here is an example jsfiddle.net/iiil/56n9s/1
We assign zero only when declaring, and do not reset when clicked. Accordingly, the alert is called only once every 3 seconds.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question