Execute function only one time in Javascript, no matter how many times it has been called. I write the following code, but does not working.
var counter = 0;
if(n.data === YT.PlayerState.BUFFERING) {
setTimeout(function() {
if(counter===0) {
r.frontPlayer.seekTo(10);
counter++;
}}, 2000);
}
setTimeoutwill only run it once. If you're running this whole block of code multiple times, then that's a different problem.var counter = 0;is in the same scope wheresetTimeoutis declared