将 setInterval 和回调传递给新变量

Passing setInterval and callback to a new variable

我将 setInterval 函数存储在一个数组中,稍后尝试将它传递给一个新变量。

this.clock = setInterval(() => {
  this.duration = this.timer.formatTime(this.userTime)
  if (this.duration === '00:00:00') {
    clearInterval(this.clock); 
    this.timer.reset();
  }
}, 1)

查看 setInterval 对象 this.clock.callback 有一个 Closure._this 对象,但我不知道如何访问它,因为它与 <function scope> 字段一起使用。

有没有办法将 setInterval 函数的当前内容传递给新变量?

如...

this.newClock = this.clock

this.newClock的倒计时时间与this.clock相同。

P.S。我刚开始在 Whosebug 上发帖。任何提出更好问题的提示或建议将不胜感激。

setInterval returns 该间隔的间隔 ID。您不能使用它来获取访问功能。您可以做的是创建一个命名函数并告诉 setInterval 调用它。然后您也可以在 setInterval 之外调用该函数。

function blah()
{
}

setInterval(blah, 1);

blah();