V
V
vizaville2015-04-23 19:03:56
Node.js
vizaville, 2015-04-23 19:03:56

How to correctly call a class method in the SetInterval function?

class Server{
 constructor(){
   this. arrayGame = []
}

Update(){
   for (let i =0; i < this.arrayGame.length; ++i){
    что то происходит
  }
}
}

I need to call the Update method every second, tell me how to call it correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya Shatokhin, 2015-04-23
@vizavill

I don't know the syntax of ES6 classes, but it seems like this

class Server{
 constructor(){
   this.arrayGame = []
   var self = this;
   setInterval(function () { self.Update() }, 1000);
 }

Update(){
   for (let i =0; i < this.arrayGame.length; ++i){
    что то происходит
  }
}
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question