Показать сообщение отдельно
  #7 (permalink)  
Старый 05.06.2019, 12:28
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,068

dima85,
class Timer {
    constructor(data) {
    this.data = data.map(obj => ({...obj,beginTime : performance.now()}));
    requestAnimationFrame(this.loop.bind(this));
    }
    loop(time){
      this.data = this.data.filter(({beginTime,duration,"console" : txt}) => {
         const end = time - beginTime >= duration;
         if(end) {
           console.log(txt)
         }
         else return true
      })
      this.data.length && requestAnimationFrame(this.loop.bind(this))
    }

    }

    let responses =
[{"duration" : 10500, "console":"test1"},
{"duration" : 14500, "console":"test3"},
{"duration" : 15000, "console":"test"}]
    new Timer(responses)
Ответить с цитированием