首页 > 解决方案 > JavaScript 递归 setTimeout 范围

问题描述

这工作正常:

let timerId = setTimeout( function tick() {
  this.oneIteration(this.eventsQueue[counter], counter)
  counter++
  if( counter == this.eventsQueue.length ) {
    clearInterval(this.iteartionInterval)
    this.stopBtnClick()
  }
  timerId = setTimeout(tick.bind(this), this.timeoutDelay)
}.bind(this), 100)

我的问题是,如何才能摆脱各种

.bind(这个)

使用带有箭头功能的更现代的方法。此处发布了此代码的示例:link to codesandbox

标签: javascriptrecursionscopesettimeoutsetinterval

解决方案


推荐阅读